Report this

What is the reason for this report?

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

Posted on June 3, 2018

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 0.0.0.0:5000 --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.

/home/whowouldwin/myproject/myproject.ini

[uwsgi]
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

/etc/systemd/system/myproject.service

[Unit]
Description=uWSGI instance to serve myproject
After=network.target

[Service]
User=whowouldwin
Group=www-data
WorkingDirectory=/home/whowouldwin/myproject
Environment="PATH=/home/whowouldwin/myproject/myprojectenv/bin"
ExecStart=/home/whowouldwin/myproject/myprojectenv/bin/uwsgi --ini myproject.ini

[Install]
WantedBy=multi-user.target

/etc/nginx/sites-available/myproject

server {
    listen 80;
    server_name 159.89.137.109;

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

I am trying to proxy my original IP address, 159.89.137.109, 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: 159.89.137.109, request: "GET / HTTP/1.1", upstream: "uwsgi://unix:///home/whowouldwin/myproject/myproject.sock:", host: "159.89.137.109"

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.



This textbox defaults to using Markdown to format your answer.

You can type !ref in this text area to quickly search our full set of tutorials, documentation & marketplace offerings and insert the link!

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.

c9.io run self bot line

First Header Second Header
Content Cell Content Cell
Content Cell Content Cell

The developer cloud

Scale up as you grow — whether you're running one virtual machine or ten thousand.

Get started for free

Sign up and get $200 in credit for your first 60 days with DigitalOcean.*

*This promotional offer applies to new accounts only.