Nginx SSL 结合Tomcat 重定向URL变成HTTP的问题

来源:互联网 发布:画流程图的软件 编辑:程序博客网 时间:2024/05/22 03:17

问题

由于要配置服务器(Nginx + Tomcat)的SSL的问题(Nginx同时监听HTTP和HTTPS),但是,如果用户访问的是HTTPS协议,然后Tomcat进行重定向的时候,却变成了HTTP.

解决办法

Nginx 配置

nginx.config

  location /xxx {       # 代理的配置,要添加以下内容       proxy_set_header Host $host;       proxy_set_header X-Real-IP $remote_addr;       proxy_set_header REMOTE-HOST $remote_addr;       proxy_set_header X-Forwarded-For $proxy_add_x_forwarded_for;       proxy_pass http://127.0.0.1:8888/xxx;       # must        # 解决https 的重定向问题       proxy_set_header X-Forwarded-Proto  $scheme;       proxy_redirect   http:// https://;   }

Tomcat 配置

server.xmlEngine模块下面配置多一个以下的Valve

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

重启服务

重启 Tomcat。

重新加载 nginx 配置

cd /usr/sbin./nginx -s reload 

重启 nginx 服务

service nginx restart

原文链接:

  • Nginx SSL 结合Tomcat 重定向URL变成HTTP的问题 1
  • Nginx SSL 结合Tomcat 重定向URL变成HTTP的问题 2