nginx 嵌套代理 https 时问题的处理
顶级 nginx 负责 https 配置,并反向代理通过 http 协议到下层 nginx
此时如果下层的 nginx 做了 rewrite redirect 的重定向,会导致 https 请求被重定向到 http 协议
location /oldpath {
rewrite ^ /newpath redirect;
}
因为 nginx 会自动补全完整路径,这样的写法跟以下是等同的
location /oldpath {
rewrite ^ $scheme://$http_host/newpath redirect;
}
但顶级 nginx 又是由 http 协议到下层 nginx,所以这里拼出来就是 http 的地址
解决方案(之一):
在顶级 nginx 代理中,添加 proxy_redirect 配置
location / {
proxy_pass http://next_nginx_path;
proxy_redirect http:// https://;
}
这样会对下层所有 http:// 内容替换为 https://。
输了你,赢了世界又如何...