七层套餐源站服务器获取真实IP
一、源站配置(nginx)
1、用X-Forwarded-For获取
proxy_set_header X-Forwarded-For $proxy_add_x_forwarded_for;
2、日志字段修改为
log_format main '$http_x_forwarded_for - $remote_addr - $remote_user [$time_local] "$request" '
'$status $body_bytes_sent "$http_referer" '
'"$http_user_agent"';
3、源站查看日志
第一个字段为客户端真实IP,第二个字段为七层套餐节点IP
二、源站配置(apache)
1、验证mod_remoteip模块
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)
如上内容,模块mod_remoteip已经安装 已经加载了
2、修改配置
在主配置文件中加入:%{X-Forwarded-For}i
路径:/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
重启httpd服务器
3、源站查看日志
第一个字段为七层套餐节点IP,第二个字段为客户端真实IP