關於nginx ssl + tomcat后 Java通過request.getScheme()獲取到http而不是https的問題,解決方案如下:
配置 Nginx 的轉發選項(需要在ssl模塊上添加上):
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-Proto $scheme;
配置Tomcat server.xml 的 Engine 模塊下配置一個 Valve:
<Valve className="org.apache.catalina.valves.RemoteIpValve" remoteIpHeader="X-Forwarded-For" protocolHeader="X-Forwarded-Proto" protocolHeaderHttpsValue="https"/>
配置雙方的 X-Forwarded-Proto 就是為了正確地識別實際用戶發出的協議是 http 還是 https。