我有一个应该始终提供 https 的服务器,并且我尝试让 nginx 自动从 http 重定向到 https。阅读此处有关此主题的其他问题后,我写了以下配置:
server {
listen 80;
return 301 https://$host$request_uri;
}
server {
listen 443 ssl;
server_name *.amazonaws.com *.mydomain.com;
ssl_certificate /home/ubuntu/mysite/ssl.cert;
ssl_certificate_key /home/ubuntu/mysite/ssl.key;
location = /favicon.ico { access_log off; log_not_found off; }
location /static/ {
autoindex on;
alias /home/ubuntu/mysite/__staticfiles;
}
location / {
include proxy_params;
proxy_pass http://unix:/home/ubuntu/mysite/mysite.sock;
proxy_set_header Host $http_host;
proxy_set_header X-Real-IP $remote_addr;
proxy_set_header X-Forwarded-For $proxy_add_x_forwarded_for;
}
}
请注意,*.amazonaws.com server_name 是为了能够使用亚马逊公共 DNS,例如“ec2-12-345-678-9.compute-1.amazonaws.com”
现在问题是:当我使用 amazon dns 输入任何 http 地址时,例如:
http://ec2-12-345-678-9.compute-1.amazonaws.com/admin
我被重定向到此处:
https://%2A.amazonaws.com/admin
如果我访问 https:
https://ec2-12-34-567-8.compute-1.amazonaws.com/admin
我到这儿了:
https://ec2-12-34-567-8.compute-1.amazonaws.com%2Cec2-12-34-567-8.compute-1.amazonaws.com/admin/
我究竟做错了什么?
谢谢,