I was pretty stuck with this thing a couple of hours. I could not get it to work. I tried everything I could think of and / or find on the Internet.
So my application is pointed to ELB (web). The ELB listens to 80 and 443 and sends traffic up to 80 (SSL terminates here) to the member instance, which is nginx.
Nginx proxies application requests to another ELB (application) in front of multiple instances. These instances trigger the cougar.
Everything works fine, except when I try to visit the URL (where I used force_ssl for this controller) using the https scheme, I get a redirect loop.
Here are my nginx configurations look like
location @{{app_name}} { proxy_set_header X-Forwarded-For $proxy_add_x_forwarded_for; proxy_set_header Host $http_host; proxy_set_header X-Forwarded-Proto $scheme; proxy_redirect off; proxy_pass http://{{app_name}}; # limit_req zone=one; access_log /var/log/nginx/access.log; error_log /var/log/nginx/error.log; }
(Obviously, app_name is being replaced by ansible.)
Instead of $scheme I tried hardcoding https and $proxy_add_x_forwarded_proto , but no one worked for me. I am still getting a loop.
Then I started checking env on rails and I see the following values ββregardless of the header set in nginx configuration.
"SERVER_PROTOCOL"=>"HTTP/1.1", "HTTP_X_FORWARDED_PROTO"=>"http", "rack.url_scheme"=>"http",
I'm not sure what I'm doing wrong. Any help appreciated! Note. I already checked all the found SO streams and no one helped!
ruby-on-rails amazon-elb nginx
Hungrycoder
source share