Apache获取前端nginx的真实用户ipnginx 前端端配置Apache 后端配置mod_rpaf: `#Apache 2.2`mod_remoteip:`Apache-2.4`nginx 前端端配置配置文件 nginx.confproxy_set_header Host $host;proxy_set_header X-Re...

Apache获取前端nginx的真实用户ip
- nginx 前端端配置
- Apache 后端配置
- mod_rpaf: `#Apache 2.2`
- mod_remoteip:`Apache-2.4`
nginx 前端端配置
配置文件 nginx.conf
proxy_set_header Host $host;
proxy_set_header X-Real-IP $remote_addr;
proxy_set_header X-Forwarded-For $proxy_add_x_forwarded_for;
proxy_set_header X-Forwarded-Proto $scheme;
Apache 后端配置
注意:
Apache获取真实IP地址有2个模块:
mod_rpaf:Apache-2.2支持;Apache-2.4不支持;
mod_remoteip:Apache-2.4自带模块;Apache-2.2 支持
yum -y install httpd httpd-devel
mod_rpaf: #Apache 2.2
安装模块
wget http://stderr.net/apache/rpaf/download/mod_rpaf-0.6.tar.gz
tar zxvf mod_rpaf-0.6.tar.gz
cd mod_rpaf-0.6
apxs -i -c -n mod_rpaf-2.0.so mod_rpaf-2.0.c
修改配置文件 httpd.conf 在末尾添加
LoadModule rpaf_module modules/mod_rpaf-2.0.so
RPAFenable On
RPAFsethostname On
RPAFproxy_ips ip地址
RPAFheader X-Forwarded-For
RPAFproxy_ips 后面添加nginx前端的ip
#若前端是阿里云slb,可以看之前的日志查看IP,一般为两个ip
重启服务
systemctl restart httpd
mod_remoteip:Apache-2.4
该模块一般默认自带
在配置文件httpd.conf末尾添加配置
LoadModule remoteip_module modules/mod_remoteip.so #加载mod_remoteip.so模块
RemoteIPHeader X-Forwarded-For #设置RemoteIPHeader头部
RemoteIPInternalProxy 112.124.159.0/24 #设置回源IP段
然后修改配置文件中的日志格式, 将%h
换成%a
如下
LogFormat "%a %l %u %t \"%r\" %>s %b \"%{Referer}i\" \"%{User-Agent}i\"" combined
LogFormat "%a %l %u %t \"%r\" %>s %b" common
然后重启服务
systemctl restart httpd
织梦狗教程
本文标题为:Apache获取前端nginx的真实用户ip


基础教程推荐
猜你喜欢
- Apache CarbonData 1.0.0发布及其新特性介绍 2023-09-11
- Centos7 nginx的安装以及开机自启动的设置 2023-09-22
- Centos 安装Django2.1 2023-09-24
- P3 利用Vulnhub复现漏洞 - Apache SSI 远程命令执行漏洞 2023-09-10
- Apache Kafka 2.5 稳定版发布,新特性抢先看 2023-09-11
- RFO SIG之openEuler AWS AMI 制作详解 2022-12-28
- 为Win2003服务器打造铜墙铁壁的方法步骤 2022-09-01
- windows环境下apache-apollo服务器搭建 2023-09-10
- Docker容器操作方法详解 2022-11-13
- 通过StatefulSet部署有状态服务应用实现方式 2022-10-01