所以这是我的配置:
server {
listen 80;
server_name *.example.com;
if ($http_x_forwarded_proto = 'http') {
return 301 https://$server_name$request_uri;
}
}
当我去example.com时,nginx将我重定向到https://example.com,但页面是一个存根nginx index.html . 如果我去www.example.com它会保持不安全,所以它根本不会被重定向 .
我做错了什么?谢谢 .
编辑:当我喜欢这篇文章时:https://aws.amazon.com/premiumsupport/knowledge-center/redirect-http-https-elb/
return 301 https:// $ server_name $ request_uri $ http_x_forwarded_proto;
然后它被重定向https://example.com/http当然它是404因为http endpoints 是愚蠢的 .
1 回答
你真的应该避免在nginx中使用“if”,它是一个性能杀手 .
你应该使用这个:
并定义您的“example.com”服务器 .
如果elb正确设置为向example.com发送443请求,并且如果你在example.com:443上有一个监听套接字就可以了 .