1. 有nginx主机做反向代理的情况下后端nginx服务主机获取真实访问物理主机的ip
真实的nginx后端服务主机需添加添加http_realip_module模块
(1)所需环境:
两台虚拟机:反向代理nginx主机:172.25.254.3
真实Nginx主机:172.25.254.1
(2)反向代理主机所作操作:
[root@server3 html]# cat index.html
server3
[root@server3 html]# /usr/local/nginx/sbin/nginx -t
nginx: the configuration file /usr/local/nginx/conf/nginx.conf syntax is ok
nginx: configuration file /usr/local/nginx/conf/nginx.conf test is successful
[root@server3 html]#
server {
listen 80;
server_name www.westos.org;
location / {
proxy_set_header X-Forwarded-For $proxy_add_x_forwarded_for;
proxy_pass http://westos;
}
}
(3)真实Nginx主机所作操作:
(4)测试:(在真机测试)
先添加域名解析
访问域名
查看server1的日志可以看到获取到了真机的ip地址