Hi i followed along on the great tutorial here:


And i was able to get things working on both a test server and on my live website.

But after a few days i got a 502 Bad Gatway Error on my domain.

I’ve spent the last two days trying to fix the problem to no avail. I’m assuming its some sort of permissions issue between NGINX and Gunicorn but have no idea what the problem might be.

The gunicorn error log is saying that it can’t connect to the sock file.

The NGINX error log is showing a connect to sock failed error.

I’ve tried to change firewall settings, user permissons, paths everything it seems and still not working.

Anyone have any idea what might be the issue here?

These answers are provided by our Community. If you find them useful, show some love by clicking the heart. If you run into issues leave a comment, or add your own answer to help others.

2 answers

Seems like the problem is in Gunicorn, so focus on that only.
What’s your Gunicorn socket file path? Seems like that’s the common problem - as described in length here:

okay so i changed the directory —per some recommendations in another post about security to this:


here is my full gunicorn.service file:

Description=gunicorn daemon

ExecStart=/home/django/chrisblog/myprojectenv/bin/gunicorn --workers 3 --bind unix:/var/log/gunicorn/chrisblog.sock chrisblog.wsgi$

and here is my nginx file

server {

    listen 80;
    server_name pythoncreate.com;

    location = /favicon.ico { access_log off; log_not_found off; }
    location /static/ {
        root /home/django/chrisblog;

    location / {
        include proxy_params;
        proxy_pass http://unix:/var/log/gunicorn/chrisblog.sock;
  • But shouldn’t this proxy_pass http://unix:/var/log/gunicorn/chrisblog.sock; be proxy_pass unix:/var/log/gunicorn/chrisblog.sock; instead?
    And I would not recommend having PID or SOCKET in the /var/log - instead put it in /run where most of the others are, like /run/gunicorn.chrisblog.sock
    Edit: Remember to have the correct access rights on the sock-file, so Gunicorn and other depending processes can read (maybe write) the file.

Submit an Answer