Nginx反向代理

后端的WEB服务器该如何配置才能获取到客户端的真实IP地址

修改配置文件

--在反代理服务器上修改配置文件
--添加 proxy_set_header X-Real-IP $remote_addr;
server {
  listen 80;
  server_name 172.16.0.132;
  
location / {
  proxy_pass http://172.16.0.186;
  proxy_set_header X-Real-IP $remote_addr;
}
}
--在后端WEB服务器上修改配置文件
--后端WEB需要安装'http_realip_module'模块才能获取真实IP
server {
  listen 80;
  server_name 172.16.0.182;
  root html;

location / {
  set_real_ip_from 172.16.0.132; #代理服务器的IP

}
}

重载配置文件

/usr/local/nginx/sbin/nginx -s reload
Last modification:February 17, 2022
If you think my article is useful to you, please feel free to appreciate