nginx 前端https +tomcat 后端 http 非80/443端口反向代理的配置方式

kaede007 3年前

来自: http://my.oschina.net/xiangzw/blog/626422


前端nginx https +tomcat http 非80端口配置方式

Nginx增加以下配置

proxy_set_header Host $host:$server_port; 非80端口 ,用80端口时 不需要$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 server.xml配置

 <Engine name="Catalina" defaultHost="localhost">

      <Valve className="org.apache.catalina.valves.RemoteIpValve"

             remoteIpHeader="X-Forwarded-For"

             protocolHeader="X-Forwarded-Proto"

             protocolHeaderHttpsValue="https"  httpsServerPort="7001"/> 非80端口时,必须增加httpsServerPort配置,不然request.getServerPort()方法返回 443.

</Engine>