I am having a real problem force rewriting my HTTP to HTTPS in nginx.
This is the same issue as rewrite http to https with ngnix behind load balancer
However I would say that my problem is that solution not working.
My configuration:
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;";
}
}
With this configuration, a request to www.myserver.com should be redirected with a 301 to https://www.myserver.com, however it isn't.
Any help much appreciated.