需要修改兩個地方
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
<Valve className="org.apache.catalina.valves.RemoteIpValve"
remoteIpHeader="X-Forwarded-For"
protocolHeader="X-Forwarded-Proto"
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