Ben Pickles. Saying stuff about stuff.

Fixing the port number in OmniAuth callbacks with a Varnish/nginx/Passenger stack

My current server setup is thus: Varnish on port 80 and nginx (with Passenger) on 8080. Unfortunately my Rails app thought it was running on port 8080 and therefore my OmniAuth/Twitter login was returning to the wrong URL - something along the lines of http://example.com:8080/auth/twitter/callback... .

I tried setting X-Forwarded-Port etc in Varnish and fastcgi_param SERVER_PORT 80; in nginx, both without success. However, if you are using Passenger then you want to set:

passenger_set_cgi_param SERVER_PORT 80;

Here are the docs - they say you can set it in an http block but that didn't work for me and I had to add it to the server block.

Anyway, this solved my problem and will hopefully help a few more people.

Posted on

Tweet