nginx tomcat SSL下的request获取信息问题

来源:互联网 发布:时时彩计划软件免费版 编辑:程序博客网 时间:2024/06/06 10:06

最近由于项目子系统比较多

所以拆分出了几个TOMCAT出来

但是客户方只给了一个端口号,非443

只能用代理的方式了刚好学习一下NGINX这个著名的WEB服务器

使用过程中,NGINX配了SSL后,在程序里的request.getServerPort取到的总是443,

网上没相关的修改默认端口的样例,只能自己查了


终于在http://tomcat.apache.org/tomcat-7.0-doc/api/org/apache/catalina/valves/RemoteIpValve.html

里找到了一个setPortHeader()的方法,

而TOMCAT7开始才有的,6.0里是没有这个方法的


详细方法如下:

NGINX配置以下:

location ~ /demo-* {
            root   html;
            index  index.html index.htm;
   proxy_pass   http://127.0.0.1:8080;
   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_set_header X-Forwarded-Port  $server_port;


        }

TOMCAT 需要在server.xml的


   <Valve   className="org.apache.catalina.valves.RemoteIpValve"
  remoteIpHeader="x-forwarded-for"
  remoteIpProxiesHeader="x-forwarded-by"
  protocolHeader="x-forwarded-proto"
  portHeader="x-forwarded-port"

  />


好了。这回正常了,未知坑继续探索

阅读全文
0 0
原创粉丝点击