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

Proper Nginx Config #26

Closed
ghost opened this issue Jun 27, 2011 · 6 comments
Closed

Proper Nginx Config #26

ghost opened this issue Jun 27, 2011 · 6 comments

Comments

@ghost
Copy link

ghost commented Jun 27, 2011

Hey guys, I have tried everything that I can read online about SSL::Enforcer, Nginx and Unicorn, but no matter what I try, I always get an infinite loop. If I use Nginx to enforce SSL, it works just fine, but I would really prefer a software based solution. Is there a recommended example Nginx ssl confg? I appreciate any and all help!

@ariejan
Copy link
Contributor

ariejan commented Oct 21, 2011

This is not a bug in rack-ssl-enforcer, but rather your Nginx setup. Nginx proxies the incoming request to Rails, but Rails is not notified about the protocol that's being use.

If you check https://github.com/tobmatth/rack-ssl-enforcer/blob/master/lib/rack/ssl-enforcer.rb#L59 you'll notice that a HTTP header is inspected to see if SSL was used or not.

In your Nginx config add the following to your location-block:

proxy_set_header   X-Forwarded-Proto https;

Restart Nginx and you're good to go.

@ghost
Copy link
Author

ghost commented Feb 16, 2012

ariejan, thanks for your reply. I made the nginx server configuration you suggested, but I am still getting the infinite loops. Here is the location stanza: https://gist.github.com/dad787fae02fed95fe1c any suggestions?

@rymai
Copy link
Collaborator

rymai commented Mar 8, 2012

@ariejan, @creativeallies Is there any news/solutions for this? I'd like to close the issue since it's not related to the gem anymore. :)

Thanks!

@flaviogranero
Copy link

Hey guys, it's working for us with this nginx config:

proxy_set_header  X-Forwarded-Proto $scheme;

@rymai
Copy link
Collaborator

rymai commented Jul 19, 2012

Awesome, thanks for the tip! I close the issue now. :)

@rymai rymai closed this as completed Jul 19, 2012
@jeffutter
Copy link

I know this is an old issue but I ran into it again when deploying to a new environment. Apparently I also need to have:

proxy_redirect off;

in my nginx config or the non-https urls will get a redirect loop.

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

4 participants