Skip to content

Getting Real IP for Layer 7 Package Origin Server

I. Origin Server Configuration (Nginx)

1. Get X-Forwarded-For

proxy_set_header X-Forwarded-For $proxy_add_x_forwarded_for;

2. Modify Log Fields

log_format main '$http_x_forwarded_for - \(remote_addr - \(remote_user [\)time_local] "\)request" '

'$status \(body_bytes_sent "\)http_referer" '

'"$http_user_agent"';

3. View Origin Server Logs

The first field is the client's real IP, and the second field is the Layer 7 package node IP

II. Origin Server Configuration (Apache)

1. Verify mod_remoteip Module

cd /etc/httpd/

cat conf.modules.d/* | grep mod_remoteip

LoadModule remoteip_module modules/mod_remoteip.so

cat conf/* | grep conf.modules

Include conf.modules.d/*.conf

apachectl -M | grep remoteip_module

remoteip_module (shared)

As shown above, the mod_remoteip module has been installed and loaded

2. Modify Configuration

Add to the main configuration file: %{X-Forwarded-For}i

Path: /etc/httpd/conf/httpd.conf

LogFormat "%h %{X-Forwarded-For}i %l %u %t \"%r\" %>s %b \"%{Referer}i\" \"%{User-Agent}i\"" combined

LogFormat "%h %{X-Forwarded-For}i %l %u %t \"%r\" %>s %b" common

Restart httpd server

3. View Origin Server Logs

The first field is the Layer 7 package node IP, and the second field is the client's real IP