Server Fault is a question and answer site for system and network administrators. It's 100% free, no registration required.

Sign up
Here's how it works:
  1. Anybody can ask a question
  2. Anybody can answer
  3. The best answers are voted up and rise to the top

How do I set environment variables so that they are available to my rails app hosted inside nginx/passenger?

share|improve this question
up vote 1 down vote accepted

I tried a few different nginx including passenger_set_cgi_param, env and fast_cgi_param. Unfortunately none of these worked for me. In the end I exported them as bash variables in the startup script I was using to launch nginx.

share|improve this answer

As mentioned above, 'sudo env VAR=VALUE nginx' solved my issue.

share|improve this answer

One way to achieve this is to replace your passenger_ruby with a wrapper script.

http {
    passenger_ruby /usr/bin/ruby


http {
    passenger_ruby /path/to/passenger_ruby

passenger_ruby is a shell script with following content:

export MY_ENV="value"
exec "/usr/bin/ruby" "$@"
share|improve this answer

Your Answer


By posting your answer, you agree to the privacy policy and terms of service.

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