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

link|improve this question
feedback

3 Answers

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" "$@"
link|improve this answer
feedback
up vote 0 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.

link|improve this answer
feedback

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

link|improve this answer
feedback

Your Answer

 
or
required, but never shown

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