502 error (socket not found) with Nginx, Ubuntu, Uwsgi, Python

June 3, 2018 1.9k views
Nginx DNS Ubuntu 16.04 Development Python Initial Server Setup

I’ve followed this tutorial on how to set up Nginx and Uwsgi on an Ubuntu droplet to have it be internet facing. I’ve done all the necessary setup; running the command uwsgi --socket --protocol=http -w wsgi:app from a terminal works fine. It causes my site to be served on the proper domain name, on port 5000 (http://mywebsite.com:5000). This isn’t ideal, so I’m trying to set it up to A) have it be detached, without me needing to manually run the command, and B) to have it not need port 5000 at the end.

I followed the rest of the tutorial, and have not been able to get it working properly. The source code of the Python application, which works just fine, is here. It’s running off of my branch.


module = wsgi:app

logto = /var/log/uwsgi/%n.log

master = true
processes = 5

socket = myproject.sock
chmod-socket = 660
vacuum = true

die-on-term = true


Description=uWSGI instance to serve myproject

ExecStart=/home/whowouldwin/myproject/myprojectenv/bin/uwsgi --ini myproject.ini



server {
    listen 80;

    location / {
        include uwsgi_params;
        uwsgi_pass unix:///home/whowouldwin/myproject/myproject.sock;

I am trying to proxy my original IP address,, to the domain name http://who.would.win. When visiting the IP address as-is, I get the following error in /var/log/nginx/error.log. It also shows a 502 Bad Gateway error on the browser.

2018/06/03 01:32:55 [crit] 12288#12288: *7 connect() to unix:///home/whowouldwin/myproject/myproject.sock failed (2: No such file or directory) while connecting to upstream, client: XXXXXX, server:, request: "GET / HTTP/1.1", upstream: "uwsgi://unix:///home/whowouldwin/myproject/myproject.sock:", host: ""

I don’t get this error when I access it through http://who.would.win. It instead shows the generic “Welcome to Ngnix!” page, and no errors, though the views are being logged in /var/log/nginx/access.log.

1 comment
2 Answers
First Header Second Header
Content Cell Content Cell
Content Cell Content Cell
Have another answer? Share your knowledge.