1、使用宝塔面板做反向代理
在反向代理中增加
proxy_set_header X-Forwarded-Proto https;
在tomcat中修改如下
<Connector port="8080" protocol="HTTP/1.1"
connectionTimeout="30000"
remoteIpHeader="X-Forwarded-For"
protocolHeader="X-Forwarded-Proto"
protocolHeaderHttpsValue="https"
redirectPort="443" />
<Valve className="org.apache.catalina.valves.RemoteIpValve"
remoteIpHeader="x-forwarded-for"
remoteIpProxiesHeader="x-forwarded-by"
protocolHeader="x-forwarded-proto"/>
<Valve className="org.apache.catalina.valves.AccessLogValve" directory="logs"
prefix="localhost_access_log" suffix=".txt"
pattern="%{X-Real-IP}i %a %t %r %s %b" resolveHosts="false" />
后边一段是打印访问的真实IP到AccessLog中的
以上已经经过测试可以使用
2、采用这个方式经测试也可以
https://blog.csdn.net/afgasdg/article/details/78925426
<Valve className="org.apache.catalina.valves.RemoteIpValve"
remoteIpHeader="X-Forwarded-For"
protocolHeader="X-Forwarded-Proto"
protocolHeaderHttpsValue="https"/>
参考:
https://blog.csdn.net/afgasdg/article/details/78925426?utm_source=blogxgwz8
https://www.cnblogs.com/zhanghaoh/p/5293158.html
https://blog.csdn.net/rkun595/article/details/71012484
服务器只开了443端口,没开80导致javaweb重定向不能访问的问题
nginx配置
增加了
tomcat配置如下
经测试可用