
我使用 Nginx 充當監聽連接埠 443 的 docker 容器內的 SSL 代理程式。
我遇到了混合內容問題,我不確定正確的解決方法是什麼:
針對資料夾(但沒有尾部斜線)的請求,例如:https://example.com/mediafiles/bar
被正確路由到第二個 NginX 實例。
但是,它會向 http url(回應標頭)發送 301:
$ curl -IL https://example.com/mediafiles/bar
HTTP/1.1 301 Moved Permanently
Server: nginx
Date: Mon, 15 Jun 2015 15:16:29 GMT
Content-Type: text/html
Content-Length: 178
Connection: keep-alive
Location: http://example.com/mediafiles/bar/
X-UA-Compatible: IE=Edge,chrome=1
HTTP/1.1 301 Moved Permanently
Server: nginx
Date: Mon, 15 Jun 2015 15:16:29 GMT
Content-Type: text/html
Content-Length: 178
Connection: keep-alive
Location: https://example.com/mediafiles/bar/
HTTP/1.1 200 OK
Server: nginx
Date: Mon, 15 Jun 2015 15:16:29 GMT
Content-Type: text/html; charset=utf-8
Content-Length: 1786
Connection: keep-alive
Vary: Accept-Encoding
Last-Modified: Wed, 18 Mar 2015 23:09:35 GMT
Vary: Accept-Encoding
ETag: "550a05af-6fa"
Accept-Ranges: bytes
X-UA-Compatible: IE=Edge,chrome=1
可能是由這個常見的 try_files 配置引起的(編輯:顯然它沒有發出重定向)。
location / {
# First attempt to serve request as file, then
# as directory, then fall back to displaying a 404.
try_files $uri $uri/ /index.php?$args;
}
我在這裡發布了完整的上游配置:https://gist.github.com/mgcrea/f149d0481ad1fa1c2207
以及相關的代理配置:https://gist.github.com/mgcrea/26ef92026a20ccc222226
此 301 到 http 資源會觸發混合內容錯誤:
混合內容:頁面位於 'https://example.com'透過 HTTPS 加載,但請求了不安全的資源'http://example.com/mediafiles/bar/'。該請求已被阻止;內容必須透過 HTTPS 提供。
有任何想法嗎?
似乎有關係:https://stackoverflow.com/questions/15555428/nginx-causes-301-redirect-if-theres-no-trailing-slash