After configuring nginx (reverse proxy) and gunicorn, env variables stop being detected (Django app on Ubuntu)


Navin
25/12/2015 9:47 am
HOME ยป Network & Servers

On an ubuntu machine hosting my Django app (with postgres backend), my env variables were prefectly detected when I fired up gunicorn as my sole webserver using the command gunicorn --bind 0.0.0.0:8080 --env DJANGO_SETTINGS_MODULE=myproject.settings myproject.wsgi:application

Next, I installed nginx and configured it to act as a reverse proxy with gunicorn (using a digital ocean guide here). There is no supervisor. This new web server configuration fired up correctly, except now it doesn't detect the env variables at all.

Imagine my env variables are awake=1 and secret=abc123. I've already tried putting export awake=1 and export secret=abc123, in /etc/default/nginx, in gunicorn.conf, in /etc/environment (which sets them globally). I also tried adding them to nginx.conf as env awake=1; and env secret=abc123;.

Nothing worked.

Now it seems that nginx

removes all environment variables inherited from its parent process except the TZ variable

Source: http://nginx.org/en/docs/ngx_core_module.html#env Could this be the reason why nothing I'm trying has come close to working? Nevertheless, echo $awake yields 1 on the command line, which tells me that perhaps the variables are set, but being bypassed or overlooked.

It's become very frustrating. Can anyone help me figure this one out? Thanks in advance.


wsgi.py:

import os
os.environ.setdefault("DJANGO_SETTINGS_MODULE", "myproject.settings")
from django.core.wsgi import get_wsgi_application
from dj_static import Cling
application = Cling(get_wsgi_application())

gunicorn.conf:

description "Gunicorn application server handling
myproject"

start on runlevel [2345]
stop on runlevel [!2345]

respawn
setuid myuser
setgid www-data
chdir /home/myuser/directory/myproject/

exec /home/myuser/.virtualenvs/myvirtualenv/bin/gunicorn
--chdir=/home/myuser/directory/ --workers 3 --bind
unix:/home/myuser/directory/myproject/myproject.sock --env
DJANGO_SETTINGS_MODULE=myproject.settings myproject.wsgi:application

/etc/nginx/sites-available/myproject:

server {
    listen 80;
    server_name myapp.cloudapp.net;

    location = /favicon.ico { access_log off; log_not_found off; }
    location /static/ {
        root /home/myuser/directory/myproject;
    }

    location / {
        include proxy_params;
        proxy_pass
http://unix:/home/myuser/directory/myproject/myproject.sock;
    }
}

Note: Please ask for more information if you need it


Related to : After configuring nginx (reverse proxy) and gunicorn, env variables stop being detected (Django app on Ubuntu)
After configuring nginx (reverse proxy) and gunicorn, env variables stop being detected (Django app on Ubuntu)
25/12/2015 9:47 am by Navin in Network & Servers

On an ubuntu machine hosting my Django app (with postgres backend), my env variables were prefectly detected when I fired up gunicorn as my sole webserver using the command gunicorn --bind 0.0.0.0:8080 --env DJANGO_SETTINGS_MODULE=myproject.settings myproject.wsgi:application

TAGS: After configuring nginx reverse proxy gunicorn
django gunicorn and nginx proxy giving 504 error
by Yserbius in Network & Servers

I went through all the related questions and could not find the answer, i went through the docs as well and tried all that i could, its my first time, hence having a hard time.
I have a simple django polls app with proper settings and static files, working locally.


<
set nginx as proxy for both apache and gunicorn at the same time
by AJ. in Network & Servers

I have all my code in django, hence using gunicorn to host django, and using nginx as reverse proxy.
I now want to host some PHP files on the same domain (or subdomain) using an nginx server as reverse proxy, and apache server.


Is it possible to reverse proxy nginx for 2 differen


Gunicorn and Django with Upstart and Nginx
by Deledrius in Network & Servers

First of all I have many Django instances setup and running like this.


In each project I have a script.sh shell script that starts gunicorn etc.:


#!/bin/bash
set -e
LOGFILE=/var/log/gunicorn/app_name.log
LOGDIR=$(dirname $LOGFILE)
NUM_WORKER
Can Django run on Gunicorn alone (no Apache or nginx)?
by highland145 in Network & Servers

I have tried just about every django + nginx tutorial on the web and I cannot get an image file to display on the screen. It's always the old story - 404 PAGE NOT FOUND. The web page loads fine but django.png in my /static/ folder does not. Not sure if it's a problem in settings.py or with nginx.


Deploying Django with gunicorn and nginx
by erlang in Network & Servers
This is a broad question but I'd like to get a canonical answer. I have been trying to deploy a site using gnunicorn and nginx in Django. After reading tons of tutorials I have been successful but I can't be sure that the steps I followed are good enough to run a site without problems or maybe there
django-gunicorn-nginx: 502 bad gateway
by Guid in Network & Servers

I'm trying to ship my web application to the server and this is my first time configuring the server. I'm using django-gunicorn-nginx setup by following this tutorial http://ijcdigital.com/blog/django-gunicorn-and-nginx-setup/ First everything was perfect and I got the django welcome page. Then I


static files with gunicorn, django and nginx
by cjdavis in Network & Servers

I have a django project and want to deploy it using gunicorn and nginx.


So far everything works, but when I add subdomains, static files are not served and my page look terrible!


If I use localhosts instead, everything works perfect!


Here I leave my nginx.conf:


Intermittent 502s with nginx+gunicorn+django
by Jammy in Network & Servers

Over the past few weeks we've been getting more and more 502 errors. Currently our stack is nginx + gunicron + django on an m1.large EC2 instance backed by a small RDS instance.


They seem to become more frequent as the request load increases. I will see the random 502 while using a br


Deploying Django project with Gunicorn and nginx
by Tom Arleth in Network & Servers
I am new to django, i would like to know how to set up my django project with nginx and gunicorn. I read this guide: http://michal.karzynski.pl/blog/2013/06/09/django-nginx-gunicorn-virtualenv-supervisor/but it doesn't work for my project.I think that it is due to the particular structure of my proj
Privacy Policy - Copyrights Notice - Feedback - Report Violation - RSS 2014 © bighow.org All Rights Reserved .