Nginx Django and Gunicorn. Gunicorn sock file is missing? Nginx Django and Gunicorn. Gunicorn sock file is missing? nginx nginx

Nginx Django and Gunicorn. Gunicorn sock file is missing?


Well, since I don't have enough rep to comment, I'll mention here that there is not a lot of specificity suggested by the missing socket, but I can tell you a bit about how I started in your shoes and got things to work.

The long and short of it is that gunicorn has encountered a problem when run by upstart and either never got up and running or shut down. Here are some steps that may help you get more info to track down your issue:

  • In my case, when this happened, gunicorn never got around to doing any error logging, so I had to look elsewhere. Try ps auxf | grep gunicorn to see if you have any workers going. I didn't.
  • Looking in the syslog for complaints from upstart, grep init: /var/log/syslog, showed me that my gunicorn service had been stopped because it was respawning too fast, though I doubt that'll be your problem since you don't have a respawn in your conf. Regardless, you might find something there.
  • After seeing gunicorn was failing to run or log errors, I decided to try running it from the command line. Go to the directory where your manage.py lives and run the expanded version of your upstart command against your gunicorn instance. Something like (Replace all of the vars with the appropriate litterals instead of the garbage I use.):

    /path/to/your/virtualenv/bin/gunicorn --name myapp --workers 4 --max-requests 10 --user appuser --group webusers --log-level debug --error-logfile /somewhere/I/can/find/error.log --bind unix:/tmp/myapp.socket myapp.wsgi

  • If you're lucky, you may get a python traceback or find something in your gunicorn error log after running the command manually. Some things that can go wrong:

    • django errors (maybe problems loading your settings module?). Make sure your wsgi.py is referencing the appropriate settings module on the server.
    • whitespace issues in your upstart script. I had a tab hiding among spaces that munged things up.
    • user/permission issues. Finally, I was able to run gunicorn as root on the command line but not as a non-root user via the upstart config.

Hope that helps. It's been a couple of long days tracking this stuff down.


I encountered the same problem after following Michal Karzynski's great guide 'Setting up Django with Nginx, Gunicorn, virtualenv, supervisor and PostgreSQL'.

And this is how I solved it.

I had this variable in the bash script used to start gunicorn via Supervisor (myapp/bin/gunicorn_start):

SOCKFILE={{ myapp absolute path }}/run/gunicorn.sock

Which, when you run the bash script for the first time, creates a 'run' folder and a sock file using root privileges. So I sudo deleted the run folder, and then recreated it without sudo privileges and voila! Now if you rerun Gunicorn or Supervisor you won't have the annoying missing sock file error message anymore!

TL;DR

  1. Sudo delete run folder.
  2. Recreate it without sudo privileges.
  3. Run Gunicorn again.
  4. ????
  5. Profit


The error could also arise when you haven't pip installed a requirement. In my case, looking at the gunicorn error logs, I found that there was a missing module. Usually happens when you forget to pip install new requirements.