我在 nginx 中强制将 HTTP 重写为 HTTPS 时遇到了真正的问题。
这与使用负载均衡器后面的 ngnix 将 http 重写为 https
然而我想说我的问题是该解决方案不起作用。
我的配置:
server {
listen 80;
server_name myserver.com *.myserver.com;
location /health-check {
proxy_set_header X-Real-IP $remote_addr;
proxy_set_header X-Forwarded-For $proxy_add_x_forwarded_for;
proxy_set_header Host $http_host;
proxy_redirect off;
proxy_next_upstream error;
proxy_pass http://localhost:8080;
break;
}
location / {
proxy_set_header X-Real-IP $remote_addr;
proxy_set_header X-Forwarded-For $proxy_add_x_forwarded_for;
proxy_set_header Host $http_host;
proxy_redirect off;
proxy_next_upstream error;
# 2) Any request that did not originally come in to the ELB
# over HTTPS gets redirected.
if ($http_x_forwarded_proto != 'https') {
return 301 https://$server_name$request_uri;
}
proxy_pass http://localhost:8080;
add_header Strict-Transport-Security "max-age=31536000; includeSubDomains;";
}
}
使用此配置,对 www.myserver.com 的请求应使用 301 重定向至https://www.myserver.com,但事实并非如此。
任何帮助都非常感谢。