UWSGI & Django 1.4 – Bad Gateway and no error

djangouwsgi

I am having trouble getting Django and uWSGI to play nice on Ubuntu (12). It seems that the wsgi is loading and then the app is immediately crashing. None of the uwsgi logs are giving me anything to go by. I am using the standard Django 1.4 wsgi with the following uwsgi configuration:

[uwsgi]
project = djangoproject
base_dir = /home/www/mywebsite.com

uid = www-data
gid = www-data
plugins = http,python

processes = 4
harakiri = 60
reload-mercy = 8
cpu-affinity = 1
max-requests =  2000
limit-as = 512
reload-on-as = 256
reload-on-rss = 192
no-orphans = True
vacuum = True
master = True

logto = /var/log/uwsgi/%n.log
catch-exceptions

virtualenv = %(base_dir)/venv
chdir = %(base_dir)
module = %(project).wsgi

socket = /run/uwsgi/%n.sock
chmod-socket = 666

Here is what my log file says:

[uWSGI] getting INI configuration from mywebsite.ini
*** Starting uWSGI 1.0.3-debian (32bit) on [Sun Oct  7 23:52:26 2012] ***
compiled with version: 4.6.2 on 20 February 2012 10:06:16
current working directory: /etc/uwsgi/apps-enabled
detected binary path: /usr/bin/uwsgi-core
limiting address space of processes...
your process address space limit is 536870912 bytes (512 MB)
your memory page size is 4096 bytes
 *** WARNING: you have enabled harakiri without post buffering. Slow upload could be rejected on post-unbuffered webservers ***
uwsgi socket 0 inherited UNIX address /run/uwsgi/mywebsite.sock fd 3
Python version: 2.7.3 (default, Aug  1 2012, 05:27:35)  [GCC 4.6.3]
Set PythonHome to /home/www/mywebsite.com/venv
Python main interpreter initialized at 0x9944570
your server socket listen backlog is limited to 100 connections
*** Operational MODE: preforking ***
PRINT STATEMENT FROM WSGI.PY
WSGI application 0 (mountpoint='') ready on interpreter 0x9944570 pid: 6130 (default app)
*** uWSGI is running in multiple interpreter mode ***
gracefully (RE)spawned uWSGI master process (pid: 6130)
spawned uWSGI worker 1 (pid: 6146, cores: 1)
set cpu affinity for worker 1 to 0
spawned uWSGI worker 2 (pid: 6147, cores: 1)
set cpu affinity for worker 2 to 1
spawned uWSGI worker 3 (pid: 6148, cores: 1)
set cpu affinity for worker 3 to 2
spawned uWSGI worker 4 (pid: 6149, cores: 1)
set cpu affinity for worker 4 to 3

I can't see anything in there which explains why the app is crashing out. I also added a print statement to the wsgi.py to ensure that it was loading correctly.

For reference, here is my wsgi:

import os

os.environ.setdefault("DJANGO_SETTINGS_MODULE", "djangoproject.settings")

# This application object is used by any WSGI server configured to use this
# file. This includes Django's development server, if the WSGI_APPLICATION
# setting points here.
from django.core.wsgi import get_wsgi_application
application = get_wsgi_application()

Best Answer

I do not think uWSGI (or Django) is crashing. uWSGI is very verbose on death/reload and your title reports a 'bad gateway' error that is another thing. Check your webserver logs maybe it is some configuration error