部署nginx获取客户端ip - log - "$http_x_forwarded_for"


1.Nginx 作为服务器时,获取客户端真实 IP 使用 http_realip_module,默认安装的 Nginx 是没有安装这个模块的,需要重新编译 Nginx 增加 --with-http_realip_module。

wget  http://nginx.org/download/nginx-1.14.0.tar.gz 
tar  zxvf nginx-1.14.0.tar.gz 
cd nginx-1.14.0
./configure --user=www --group=www --with-http_stub_status_module --without-http-cache --with-http_ssl_module --with-http_realip_module
make
make install

2.修改 nginx.conf。

 
vi /etc/nginx/nginx.conf
fastcgi connect_timeout 300;
fastcgi send_timeout 300;
fastcgi read_timeout 300;
fastcgi buffer_size 64k;
fastcgi buffers 4 64k;
fastcgi busy_buffers_size 128k;
fastcgi temp_file_write_size 128k;

set_real_ip_from IP地址;(这个IP地址首先不是负载均衡提供的公网IP,具体IP多少可以查看之前nginx日志,如果有多个都要写上。)
real_ip_header X-Forwarded-For;

参考:https://cloud.tencent.com/document/product/214/3728


免责声明!

本站转载的文章为个人学习借鉴使用,本站对版权不负任何法律责任。如果侵犯了您的隐私权益,请联系本站邮箱yoyou2525@163.com删除。



 
粤ICP备18138465号  © 2018-2025 CODEPRJ.COM