Take the 2-minute tour ×
Server Fault is a question and answer site for system and network administrators. It's 100% free, no registration required.

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

share|improve this question

3 Answers 3

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

to

http {
    ...
    passenger_ruby /path/to/passenger_ruby

passenger_ruby is a shell script with following content:

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

Your Answer

 
discard

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.