nginx反向代理到tomcat, 使用proxy_set_header Host $host:$server_port; 可以把端口带过去, 但是,发现Request.getServerPort()总是返回80端口,而不是访问nginx的6000端口。 ------------ debug发现,port值开始是6000,后来变成了80。 继续debug发现,判断了Header项目:protoHeader, 如果是https,port变为443,如果是http,port变成80. ------------ 查看nginx配置文件,发现写了 proxy_set_header X-Forwarded-Proto $scheme; 去掉,问题解决。 -------------------------------------------- The X-Forwarded-Proto (XFP) header is a de-facto standard header for identifying the protocol (HTTP or HTTPS) that a client used to connect to your proxy or load balancer. Your server access logs contain the protocol used between the server and the load balancer, but not the protocol used between the client and the load balancer. To determine the protocol used between the client and the load balancer, the X-Forwarded-Proto request header can be used. -------------------------------------------- 另外,可以参考这个: https://tomcat.apache.org/tomcat-8.5-doc/config/filter.html 可以配置RemoteIpFilter,获取remote端的原始ip和端口
|