In this question: rewrite http to https with ngnix behind load balancer
the question is how to force SSL for nginx servers behind a loadbalancer. The problem with this setup is that the loadbalancer handles SSL and has a non SSL connection with the webservers/nodes.
So it looks at the http-x-forwarded-proto header. The accepted answer works fine except that it uses an if like so:
if ($http_x_forwarded_proto = "http") {
rewrite ^/(.*)$ https://mydomain.com/$1 permanent;
}
which is evil: http://wiki.nginx.org/IfIsEvil
Is there a better way to do this without an if?
One possible solution would be to force ssl at the loadbalancer, but this loadbalancer is managed by our hoster, which makes changes more tedious, im hoping for an answer which doesn require changes to the loadbalancer