How do I get nginx to issue 301 requests to HTTPS location, when SSL handled by a load-balancer?

Nginx doesn't look for HTTP_X_FORWARDED_PROTO and it's not a bug. It's just lack of such functionality.

You should configure your frontend to adjust the location header in responses, or replace it with another nginx (since nginx itself is a great load-balancer and SSL-terminator).


Looks like the LB is doing SSL termination and nginx just gets a HTTP request. Nginx doesn't modify any of the HTTP headers it receives. You can do this using rewrite rules which checks whether HTTP_X_FORWARDED_PROTO is set or not and then accordingly rewrites the request. FYI nginx doesn't supported nested or complex "if" statements therefore you'll have to resort to the method described in the link below.

http://rosslawley.co.uk/2010/01/nginx-how-to-multiple-if-statements/