環境:
NGINX(HTTPS) -->TOMCAT
報錯:
錯誤:Mixed Content: The page at ‘https://XXX’ was loaded over HTTPS, but requested an insecure........
主體框架可以正常加載, 但是內部借口和 iframe 里面的內容以及靜態資源全部報錯
解決方法:
1.讓nginx傳遞給后端的轉發內攜帶協議信息
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;
重點在最后一條
2.讓tomcta識別https
修改tomcat server.xml 里的 Engine 模塊下配置一個 Value:
<Valve className="org.apache.catalina.valves.RemoteIpValve"
remoteIpHeader="X-Forwarded-For" protocolHeader="X-Forwarded-Proto"
protocolHeaderHttpsValue="https"/>
其中
X-Forwarded-Proto 屬性是為了讓tomcat 識別請求是http的還是https的