1. 描述
-
問題: 瀏覽器打開
https://www.aa.com/aaa.html
,然後跳轉到http://www.aa.com/aaa.html
-
網站架構:用戶–https—> nginx代理 —http—→ tomcat/nginx+php
nginx待遇發給後端的請求是http協議,後端程序跳轉獲取到的協議是http,返回一個redirect(http header中帶Location:http://www.aa.com/aaa.html),瀏覽器收到location,跳轉到了location指定的地方。
2. 解決方法
2.1. 解決方法1
在nginx代理中增加一個header,標誌用戶請求是http還是https,後端獲取header決定跳轉到http/https頁面。這個方法需要修改nginx配置和程序,不推薦,但是可以解決問題。
2.2. 解決方法2
nginx代理中配置proxy_redirect
proxy_redirect http:// $scheme://;
以上指令會將後端響應header location
內容中的http:替換成用戶端協議https:
。 NGINX訪問https跳轉到http的解決了~