1

I'm looking to redirect from HTTP to HTTPS. My Nginx server sits behind a load balancer which will terminate SSL for me and send all traffic (HTTP and HTTPS) to port 80. The only evidence I will have to indicate whether the original request made was HTTP or HTTPS is via the X-Forwarded-For header that is set by the load balancer. Is there a built-in, inexpensive way to handle redirection in Nginx when the original request was on HTTP? Keep in mind, I'll only have a server set up for port 80.

3

Assuming that you're guaranteeing that the X-Forwarded-For header is only set for SSL traffic ...

if ($http_x_forwarded_for) {
    return 301 https://$host$request_uri;
}

Although this is arguably something you should do at the balancer.

  • Thanks. I ended up deciding that termination of SSL at the LB isn't a good idea for my use-case and instead will be creating a 80 and a 443 server in Nginx. – orokusaki Jun 8 '13 at 3:12
  • One thing to note about terminating SSL at the nginx layer, you'll likely lose the client IP altogether with that solution. It depends on the load-balancer you're using, but if you're load-balancing SSL, then you'll need to do TCP-level load-balancing (as opposed to HTTP-level). Best of luck :) – chrskly Jun 8 '13 at 12:28
  • Oh :/ thanks again, that's good to know. Man, people like you make the tech world go round. – orokusaki Jun 9 '13 at 0:28

Your Answer

By clicking "Post Your Answer", you acknowledge that you have read our updated terms of service, privacy policy and cookie policy, and that your continued use of the website is subject to these policies.

Not the answer you're looking for? Browse other questions tagged or ask your own question.