我正在尝试将http重定向到https,并且我有这样的配置:
files:
"/etc/nginx/conf.d/robots.conf":
mode: "000544"
owner: root
group: root
content: |
server {
listen 80;
server_name example.com;
location =/health {
return 200 "health-check";
}
location / {
if ($http_x_forwarded_proto != "https") {
return 301 https://$host$request_uri;
}
}
}
server {
listen 80 default_server;
server_name www.example.com;
location =/health {
return 200 "health-check";
}
location / {
if ($http_x_forwarded_proto != "https") {
return 301 https://$host$request_uri;
}
}
}但当我转到http://example.com或http://www.example.com时没有重定向...我尝试了多种设置,但似乎从未完全正常工作过。
发布于 2017-08-21 18:17:38
要做到这一点,最好的方法是如下设置您的配置
server {
listen 80;
server_name my.example.com;
return 301 https://$server_name$request_uri;
}
server {
listen 443 ssl;
server_name my.example.com;
# add Strict-Transport-Security to prevent man in the middle attacks
add_header Strict-Transport-Security "max-age=31536000";
[....]
}https://stackoverflow.com/questions/45794392
复制相似问题