需要修改两个地方
nginx 的修改
location / {
proxy_pass http://test-server;
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;
}
tomcat需要改修改
在server.xml的Engine模块下面配置中上的Valve,如果有端口也要设置httpsServerPort
<Valve className="org.apache.catalina.valves.RemoteIpValve"
remoteIpHeader="X-Forwarded-For"
protocolHeader="X-Forwarded-Proto"
internalProxies="nginx 的ip"
httpsServerPort="1443"
protocolHeaderHttpsValue="https"/>
这样在java开发中redirect中的地址都会是https,如果用http访问,也会是http的
参考http://www.siven.net/posts/d925bb5d.html#%E5%AE%9E%E8%B7%B5%E4%BA%8Ctomcat%E6%96%B0%E5%A2%9E%E9%85%8D%E7%BD%AE