I have a server that should always serve https and I try to make nginx automatically redirect from http to https. reading other questions on this subject here, I wrote the following config:
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;
}
}
note that the *.amazonaws.com server_name is so I'll be able to use amazon Public DNS, eg "ec2-12-345-678-9.compute-1.amazonaws.com"
now here's the problem: when I enter any http address with the amazon dns, for example this:
http://ec2-12-345-678-9.compute-1.amazonaws.com/admin
I'm getting redirected to this:
https://%2A.amazonaws.com/admin
and if I go to https:
https://ec2-12-34-567-8.compute-1.amazonaws.com/admin
I'm getting here:
https://ec2-12-34-567-8.compute-1.amazonaws.com%2Cec2-12-34-567-8.compute-1.amazonaws.com/admin/
what am I doing wrong?
thanks,