Nginx代理Tomcat获取真实协议、IP

Nginx配置文件中,在location内配置

proxy_set_header Host $host:$server_port;
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;

Tomcat conf/server.xml的Host标签中增加一行配置(处理https获取到的是http)

<Valve className="org.apache.catalina.valves.RemoteIpValve" protocolHeader="X-Forwarded-Proto"/>

 

posted @ 2023-02-20 11:38  甜8筒  阅读(101)  评论(0编辑  收藏  举报