nginx代理转发,服务端获取客户端真实IP
nginx转发配置
在使用nginx转发时如果不配置一些信息服务端获取不了客户端真实IP
location /api {
proxy_pass http://IP地址:8080;
#获取客户端真实IP
proxy_set_header Host $host;
proxy_set_header X-Real-IP $remote_addr;
proxy_set_header X-Forwarded-For $proxy_add_x_forwarded_for;
proxy_set_header X-Forwarded-Proto $scheme;
proxy_redirect off;
}
当使用Nginx进行代理转发时,需要配置proxy_set_header以传递客户端的真实IP。在location块中,通过设置`proxy_set_headerHost$host;`,`proxy_set_headerX-Real-IP$remote_addr;`,`proxy_set_headerX-Forwarded-For$proxy_add_x_forwarded_for;`和`proxy_set_headerX-Forwarded-Proto$scheme;`,可以确保服务端能获取到请求的原始来源。关闭proxy_redirect以保持原始URL信息。
357

被折叠的 条评论
为什么被折叠?



