How can I test if gunicorn is working and communicating with nginx?
<p>I'm deploying my first attempt at using django+gunicorn+nginx. </p>

<ul>
<li>I have django working (<code>curl -XGET http://127.0.0.0.1:8000</code> works fine if I run the development server).</li>
<li>I have nginx working for static content (for example I can retrieve <code>http://example.com/static/my_pic.png</code> in my browser).</li>
<li>I'm not getting any wsgi content from my website, and I haven't been able to find a good troubleshooting guide (does it just work for everyone else?!). I start gunicorn using supervisor, which reports that it is indeed running:</li>
</ul>

<p>(in shell:)</p>

<pre><code>supervisorctl status my_app
my_app                   RUNNING    pid 1002, uptime 0:29:51
</code></pre>

<p>Here's the boilerplate script I used to start it:</p>

<pre><code>#!/bin/bash
#script variables
NAME="gunicorn_myapp"                      # Name of process
DJANGODIR=/webapps/www/my_project          # Django project directory
SOCKFILE=/webapps/www/run/gunicorn.sock    # communicte using this socket
USER=app_user                              # the user to run as
GROUP=webapps                              # the group to run as
NUM_WORKERS=3
DJANGO_SETTINGS_MODULE=my_project.settings # settings file
DJANGO_WSGI_MODULE=my_project.wsgi         # WSGI module name

# Activate the virtual environment
cd $DJANGODIR
source ../bin/activate
export DJANGO_SETTINGS_MODULE=$DJANGO_SETTINGS_MODULE
export PYTHONPATH=$DJANGODIR:$PYTHONPATH

# Create the run directory if it doesn't exist
RUNDIR=$(dirname $SOCKFILE)
test -d $RUNDIR || mkdir -p $RUNDIR

exec ../bin/gunicorn ${DJANGO_WSGI_MODULE}:application \
  --name $NAME \
  --workers $NUM_WORKERS \
  --user=$USER --group=$GROUP \
  --bind=unix:$SOCKFILE
</code></pre>

<p>Here's the (condensed) nginx config file:</p>

<pre><code>upstream my_server {
  server unix:/webapps/www/run/gunicorn.sock fail_timeout=10s;
}
server {
        listen 80;
        server_name www.example.com;
        return 301 $scheme://example.com$request_uri;
}
server {
    listen   80;
    server_name example.com;
    client_max_body_size 4G;
    access_log /webapps/www/logs/nginx-access.log;
    error_log /webapps/www/logs/nginx-error.log;

    location /favicon.ico { access_log off; log_not_found off; }

    location /static/ {
        autoindex on;
        alias   /webapps/www/my_project/my_app/static/;
    }

    location /media/ {
        autoindex on;
        alias   /webapps/www/my_project/my_app/media/;
    }

    location / {
        proxy_pass         http://my_server;
        proxy_redirect     off;
        proxy_set_header X-Forwarded-For $proxy_add_x_forwarded_for;
        proxy_set_header X-Forwarded-Proto https;
        proxy_set_header Host $http_host;
        proxy_redirect off;
        if (!-f $request_filename) {
            proxy_pass http://example.com;
            break;
        }
    }

    location  /robots.txt {
        alias /webapps/www/my_project/my_app/static/robots.txt ;
    }
    # Error pages
    error_page 500 502 503 504 /500.html;
    location = /500.html {
        root /webapps/www/my_project/my_app/static/;
    }
}
</code></pre>

<p>So: gunicorn is running, nginx is running ... what tests (and how?) should I perform to determine if gunicorn is doing the wsgi stuff properly (and if nginx is proxying the said stuff through correctly)?</p>

<p>Edit: I've narrowed the problem down to the communication between gunicorn and nginx via the unix socket. If I change the $SOCKFILE to be bound to <code>0.0.0.0:80</code> and stop nginx, then the app's pages are served from my website. The bad news is that the socket file strings are exactly the same between the two conf files, so I don't know why they aren't communicating. I suppose this means nginx isn't correctly fetching and passing the data through then?</p>