windows 下 nginx-1.12.1 实现 http 转 https。 nginx.conf
server {
listen 80;
server_name *.cn;
rewrite ^(.*)$ https://$host$1 permanent;
}
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-Scheme $scheme;
tomcat 的 server.xml 增加:
<Valve className="org.apache.catalina.valves.RemoteIpValve"
remoteIpHeader="X-Forwarded-For"
protocolHeader="X-Forwarded-Proto"
protocolHeaderHttpsValue="https"/>
jsp 中:String path = request.getContextPath(); String basePath = request.getScheme() + "://" request.getServerName() + ":" + request.getServerPort() 取到的仍然是 http,不是 https