Nginx SSL+tomcat集群,request.getScheme() 取到https正確的協議


關於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。

 


免責聲明!

本站轉載的文章為個人學習借鑒使用,本站對版權不負任何法律責任。如果侵犯了您的隱私權益,請聯系本站郵箱yoyou2525@163.com刪除。



 
粵ICP備18138465號   © 2018-2025 CODEPRJ.COM