How to set environment variables for nginx to read? How to set environment variables for nginx to read? nginx nginx

How to set environment variables for nginx to read?


You can define environment variable inside of supervisor's config with directive environment=VAR1=<VAR1>,VAR2=<VAR2>

Something like that:

[program:gunicorn]directory=/home/<USER>/.virtualenvs/<DOMAIN>/<PROJECT>/command=/home/<USER>/.virtualenvs/<DOMAIN>/bin/gunicorn <PROJECT>.wsgi:application -c      /home/<USER>/.virtualenvs/<DOMAIN>/<PROJECT>/<APP>/gunicorn_conf.pyuser = <USER>environment=SECRET_KEY=<SECRET_KEY>


you could load Environment Variable through a file:

create your own environment file in your app folder:

vim /home/ubuntu/workspace/apps/myapp/envfiles/myenvironment

add your environment varibles into that file:

APP_ENVIRONMENT="dev"

SECRET_KEY="mysecret_key"

Then load this environment into your gunicorn service file:

 sudo vim /etc/systemd/system/gunicorn.service

Configure your environment file in [Service] blog

 [Service] .... EnvironmentFile=/home/ubuntu/workspace/apps/myapp/envfiles/myenvironment