7.实现反向代理客户端IP透传

7.实现反向代理客户端IP透传

 

 

#第一个代理服务器

[root@centos8 ~]#vim /apps/nginx/conf/conf.d/pc.conf

server {

location / {

proxy_pass http://10.0.0.18;

proxy_set_header X-Forwarded-For $proxy_add_x_forwarded_for;

}

}

 

#第二个代理服务器

[root@centos8 ~]#vim /apps/nginx/conf/conf.d/pc.conf

server {

location / {

proxy_pass http://10.0.0.28;

proxy_set_header X-Forwarded-For $proxy_add_x_forwarded_for;

}

}

 

#后端服务器

[root@CentOS8 ~]# echo "i am real webserver" > /var/www/html/index.html

[root@CentOS8 ~]# vim /etc/httpd/conf/httpd.conf

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

[root@CentOS8 ~]# systemctl restart httpd

 

#测试访问

[root@centos7 ~]# curl www.magedu.org

i am real webserver

 

#后端服务器查看日志

[root@CentOS8 ~]# tail -f /var/log/httpd/access_log

"10.0.0.7, 10.0.0.8"  10.0.0.18 - - [14/Aug/2022:14:12:10 +0800] "GET / HTTP/1.1" 200 20 " 34 "-" "curl/7.29.0"

posted @ 2022-08-15 14:26  惊起千层浪  阅读(88)  评论(0编辑  收藏  举报