3

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

opsb
  • 163
  • 2
  • 6

4 Answers4

2

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

1

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.

opsb
  • 163
  • 2
  • 6
1

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" "$@"
Gaku Ueda
  • 111
  • 1
0

You can try dotenv gem which loads the env vars from a file of your choice.

mukesh
  • 1
  • 1