X-Forwarded-Proto for Rails behind nginx behind ELB -


i'm pretty stuck thing couple of hours. no way make working. tried can think of and/or found online.

so, application pointed elb (web). elb listens 80 , 443 , sends traffic 80 (ssl terminated here) member instance(s) nginx.

nginx proxies app requests elb (app) in front of multiple instances. these instances run puma.

everything works fine except when try visiting url (where used force_ssl controller) https scheme, redirection loop.

here nginx configs 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 gets substituted ansible.)

instead of $scheme, tried hardcoding https , $proxy_add_x_forwarded_proto none worked me. still loop.

then started inspecting env in rails , see following values regardless of header set in nginx config.

"server_protocol"=>"http/1.1", "http_x_forwarded_proto"=>"http", "rack.url_scheme"=>"http", 

i'm not sure i'm doing wrong. appreciated! note: i've checked found threads , none helped!

i found solution works (though i'm not sure if it's right).

elb listener settings

so if setup tcp listener on 8080:8080 , use nginx's upstream settings, working fine. means web instances connecting app elb on tcp 8080. see x-forwarded-proto passed correctly.

i've added listener 80 elb used cloudfront's origin connects 80.


Comments

Popular posts from this blog

java - UnknownEntityTypeException: Unable to locate persister (Hibernate 5.0) -

python - ValueError: empty vocabulary; perhaps the documents only contain stop words -

ubuntu - collect2: fatal error: ld terminated with signal 9 [Killed] -