網站部署了流量代理服務(例如Web應用防火牆、DDoS高防、CDN)后,
源站服務器可以通過解析回源請求中的X-Forwarded-For記錄,獲取客戶端的真實IP。
1,查看原來nginx的安裝模塊
./nginx -V
沒有安裝
2,重新編譯原來的nginx
cd /tmp/nginx-1.18.0
./configure --prefix=/usr/local/nginx --with-http_stub_status_module --without-http-cache --with-http_ssl_module --with-http_realip_module
make
make install
./nginx -V
安裝成功
3,添加nginx的realip配置
set_real_ip_from 47.101.16.64/27;
real_ip_header X-Forwarded-For;
real_ip_recursive on;
以及 nginx的日志格式在log_format
中添加http_x_forwarded_for字段,替換默認的remote_address字段
4,重啟nginx
./nginx -s reload