Take the 2-minute tour ×
Server Fault is a question and answer site for professional system and network administrators. It's 100% free, no registration required.

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.

share|improve this question

1 Answer 1

up vote 1 down vote accepted

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.

share|improve this answer
    
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

 
discard

By posting your answer, you agree to the privacy policy and terms of service.

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