2

I just upgraded from nginx 1.4.1 to 1.8.0 (along with an upgrade to Phusion Passenger 5.0.13). With that change the $scheme variable from our configuration no longer seems be set.

The nginx configuration looks something like this:

server {
     listen 80;
     listen 443;
     ssl on;

     server_name app.example.com;

     passenger_enabled on;
     passenger_env_var HTTP_X_FORWARDED_PROTO $scheme;

     proxy_set_header X-Forwarded-Proto $scheme;

     ...
}

When I inspect request.env['HTTP_X_FORWARDED_PROTO'] or request.headers['X-Forwarded-Proto'] in the Rails application, I get the literal "$scheme", not "http" or "https".

I have tried both proxy_set_header and passenger_set_header and have the same results.

1 Answer 1

2

This issue here is that I was setting the environment variable as well as the header. Removing this line fixed this:

passenger_env_var HTTP_X_FORWARDED_PROTO $scheme;

This is caused by the fact that passenger_env_var is evaluated at the beginning of the application rather than on each request. Because $scheme isn't defined at that time it was set there.

I don't know why the header was also pre-set but I suspect it has something to do with the fact that Passenger tries to sync the headers and environment variables to mimic a CGI environment.

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.