nginx後端web服務器獲取用戶真實ip

前端代理是nginx代理,在server配置文件中配置:

 proxy_set_header Host $host;
 proxy_set_header X-Real-IP $remote_addr;
 proxy_set_header REMOTE-HOST $remote_addr;
 proxy_set_header X-Forwarded-For $proxy_add_x_forwarded_for; 
proxy_set_header    HTTP_X_FORWARDED_FOR      $remote_addr;

後端的nginx需要重新編譯:

./configure --prefix=/usr/cmcc/nginx --with-http_stub_status_module --with-http_ssl_module --with-http_realip_module

然後在http目錄裏面加:

default_type  application/octet-stream;
#代理ip
set_real_ip_from 127.0.0.1; 
real_ip_header X-Forwarded-For;
real_ip_recursive on;

ok,這樣後端nginx web服務器日誌裏面顯示的就是真實的客戶端訪問ip了。

發表評論
所有評論
還沒有人評論,想成為第一個評論的人麼? 請在上方評論欄輸入並且點擊發布.
相關文章