nginx 安装realIp模块
1,查看原来nginx的安装模块
./nginx -V
--prefix=/usr/local/nginx --with-http_stub_status_module --with-http_ssl_module --with-pcre=/usr/local/src/pcre-8.35 --add-module=/usr/local/src/nginx-sticky-module-ng
2,编译原来的nginx
cd /usr/local/src/nginx-1.16.1
./configure --prefix=/usr/local/nginx --with-http_stub_status_module --with-http_ssl_module --with-http_realip_module --with-pcre=/usr/local/src/pcre-8.35 --add-module=/usr/local/src/nginx-sticky-module-ng
make
make install
3, 查看是否安装好模块
./nginx -V
--prefix=/usr/local/nginx --with-http_stub_status_module --with-http_ssl_module --with-http_realip_module --with-pcre=/usr/local/src/pcre-8.35 --add-module=/usr/local/src/nginx-sticky-module-ng
4,增加nginx的realIP配置
set_real_ip_from 172.30.1.23;
set_real_ip_from 172.30.2.182;
real_ip_header X-Forwarded-For;
real_ip_recursive on;
这个的前提是nginx的日志格式如下
log_format my_log_format '$remote_addr - $remote_user [$time_local] "$request" '
'$status $body_bytes_sent "$http_referer" '
'"$http_user_agent" "$http_x_forwarded_for" "$upstream_addr" "$request_time"';
本文来自博客园,作者:春江潮水连海平,转载请注明原文链接:https://www.cnblogs.com/alonewaiting/p/13644669.html