Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Infinite redirects behind AWS ELB #82

Closed
gnitnuj opened this issue Jul 7, 2015 · 5 comments
Closed

Infinite redirects behind AWS ELB #82

gnitnuj opened this issue Jul 7, 2015 · 5 comments

Comments

@gnitnuj
Copy link
Contributor

gnitnuj commented Jul 7, 2015

Pretty sure I have NGINX config correct.

Started with config.middleware.use Rack::SslEnforcer, :except_environments => 'development', :except => [/.*\/demo$/, /.*\/preview$/, /.*\/debug$/], :force_secure_cookies => false, :strict => true, and wasn't hitting AWS ELB.

So I decided to take baby steps instead...

Switched over to config.middleware.use Rack::SslEnforcer, :redirect_to => "http(s)://project_url" as proposed by the behind a proxy section, and found out that ELB wasn't able to pass health checks because they are always done via http.

So I added :except_agents => 'ELB-HealthChecker/1.0' in order to exempt the ELB health checks, and am now getting redirects again.

I'm going to resume solving this tomorrow with fresh idea, but any help would be appreciated!

@tobmatth
Copy link
Owner

tobmatth commented Jul 7, 2015

I am not familiar with AWS ELB, but setting [1] X-Forwarded-Proto as described in [2] might help...

[1] https://github.com/tobmatth/rack-ssl-enforcer#nginx
[2] http://docs.aws.amazon.com/ElasticLoadBalancing/latest/DeveloperGuide/x-forwarded-headers.html

@gnitnuj
Copy link
Contributor Author

gnitnuj commented Jul 7, 2015

@tobmatth, I'll give that a try later today and keep this thread updated!

@gnitnuj
Copy link
Contributor Author

gnitnuj commented Jul 7, 2015

For all those behind AWS ELB, this what what did it for us.

config.middleware.use Rack::SslEnforcer,
                          # this ignores elb healthchecks and development env
                          # elb healthchecks aren't forwarded requests, so it wouldn't have forwarded proto
                          # same goes when running without a proxy (like dev locally)
                          ignore: lambda { |request| request.env["HTTP_X_FORWARDED_PROTO"].blank? },
                          strict: true

@tobmatth
Copy link
Owner

tobmatth commented Jul 8, 2015

Glad you figured it out. Just merged your PR, thanks!

@tobmatth tobmatth closed this as completed Jul 8, 2015
@gnitnuj
Copy link
Contributor Author

gnitnuj commented Jul 8, 2015

No problem! I'm hoping it'll at the very least point people in the right direction. And for those behind Amazon ELB specifically, they'll be able to copy and paste and be on their way! :)

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants