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!