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 have a rails app on 2 EC2 Instances running nginx behind an Amazon Elastic Load Balancer. I'd like to force HTTPS, which was working fine before I added in the Load Balancer. Now I can't quite figure out how to do it.

My load balancer has 2 listeners: 80 to 80 and 443 to 80 (with an ssl cert).

I tried adding the following rewrite rule to the nginx config, but it didn't seem to work:

if ($http_x_forwarded_proto != 'https') {
  rewrite ^(.*) https://$host$1 permanent;

Any help would be greatly appreciated!

share|improve this question
You'll probably have an easier time if you forward 443 to 443. –  ceejayoz Jan 9 '13 at 15:33
You know, I had already tried that and got an error. So I tried again and realized what I did incorrectly last time: I typed in port 443 but didn't actually select https from the "Instance Protocol" drop-down. This fixed it - thanks! –  Adam Jan 9 '13 at 17:55

Your Answer


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

Browse other questions tagged or ask your own question.