如何获取来访者的真实IP
7层获取真实IP
1、在elb的监听器中设置使用 HTTP 协议
2、在后端apache中增加配置
[root@ecs-web ~]# vim /etc/httpd/conf.modules.d/00-remoteip.conf
LoadModule remoteip_module modules/mod_remoteip.so
RemoteIPHeader X-Forwarded-For
RemoteIPInternalProxy 100.125.0.0/16
3、注释掉 00-base.conf 中46行的
#LoadModule remoteip_module modules/mod_remoteip.so
4、修改 httpd.conf 配置文件
LogFormat “%a %h %l %u %t “%r” %>s %b “%{Referer}i” “%{User-Agent}i”” combined
5、测试配置文件语法没有问题的时候重启服务
[root@ecs-web ~]# apachectl -t
[root@ecs-web ~]# systemctl restart httpd
查看日志
nginx:
重新编译添加 realip 参数
./configure --prefix=/usr/local/nginx --user=nginx --group=nginx --with-http_ssl_module --with-http_realip_module
编辑 nginx.conf 添加
set_real_ip_from 100.125.0.0/16;
real_ip_header X-Forwarded-For;
重启服务
/usr/local/nginx/sbin/nginx -s reload
查看日志
############################################################
四层负载均衡
mkdir -p mkdir -p /lib/modules/
(
u
n
a
m
e
−
r
)
/
e
x
t
r
a
/
n
e
t
/
t
o
a
c
p
t
o
a
.
k
o
.
x
z
/
l
i
b
/
m
o
d
u
l
e
s
/
(uname -r)/extra/net/toa cp toa.ko.xz /lib/modules/
(uname−r)/extra/net/toacptoa.ko.xz/lib/modules/(uname -r)/extra/net/toa/
depmod -a
lsmod
modinfo toa
重启服务
/usr/local/nginx/sbin/nginx -s reload
参考华为云文档:
https://support.huaweicloud.com/test-usermanual-elb/zh-cn_topic_0172675020.html