部署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