How do I fix this 502 Bad Gateway error when setting up Django project on Ubuntu 14.04.5 box?

I'm trying to set up WSGI/nginx with a Django project, but am getting a 502 error. Seems like there's a problem finding the .sock file. Here's more info that should help illustrate my problem.

Anyone know what I need to fix to get rid of the error so my site displays correctly?

1 Reply

Everything in Unix is a file. Its arguably one of its greatest strengths. This holds true for unix domain sockets. Its why its complaining that it can't find a file.

If I look at your nginx conf…

server {
    listen 80;

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

    location / {
        include         uwsgi_params;
        uwsgi_pass      unix:/home/django/FOLDER/product_blog/product_blog.sock;

We see you are using the uwsgi_pass directive to instruct nginx to forward requests for / to a unix domain socket. This socket is addressed by a file location.

In your uwsgi config…

project = product_blog
base = /home/django

chdir = %(base)/%(project)
home = %(base)/Env/%(project)
module = %(project).wsgi:application

master = true
processes = 2

socket = %(base)/%(project)/%(project).sock
chmod-socket = 664
vacuum = true

Through some substitution you instruct uwsgi to install a domain socket file at /home/django/product_blog/product_blog.sock. In order for nginx to connect to that socket there must be a file in the correct location with the correct privileges. When you start uwsgi it should create the *.sock file in the specified location.

things to try

  1. Make sure you are using a valid file path in your uwsgi.conf(including the directories)
  2. Start uwsgi and make sure your *.sock file is in the correct location
  3. Make sure the proxy_pass directive in nginx is pointing to this file.


Please enter an answer

You can mention users to notify them: @username

You can use Markdown to format your question. For more examples see the Markdown Cheatsheet.

> I’m a blockquote.

I’m a blockquote.

[I'm a link] (

I'm a link

**I am bold** I am bold

*I am italicized* I am italicized

Community Code of Conduct