UPDATE: I saw questions related to the /tmp directory, and a comment mentioned moving the socket out of /home as well. It didn't fix the problem.

(Additional updates at bottom of post)

I have a ubuntu 16.04 vm on azure I'm using to host a flask application using uwsgi as the server and nginx as the reverse proxy, following this guide...


The problem is I'm getting a 502 Bad Gateway when I try to connect to the server at its ip with a web browser on port 80. When I check the logs it says that nginx cannot find the unix socket I specified in the config file.

The error is...

2016/08/29 23:23:20 [crit] 2792#2792: *120 connect() to unix:///home/me/appname/appname/appname.sock failed (2: No such file or directory) while connecting to upstream, client: ip.goes.in.here, server: here.goes.the.ip, request: "GET /favicon.ico HTTP/1.1", upstream: "uwsgi://unix:///home/me/appname/appname/appname.sock:", host: "the.ip.goes.here", referrer: "http://all.of.teh.ips/"

My server block looks like this...

server {
  listen 80;
  server_name ip.address.goes.here;

  location / {
    include uwsgi_params;
    uwsgi_pass unix:/etc/appname.sock;

my app.ini file looks like this...



master = true
processes = 5

socket = /etc/appname.sock
chmod-socket = 660
vacuum = true

die-on-term = true

my .service file looks like this...


Description=UWSGI instance to serve app


ExecStart=/home/me/appnam/uwsgi --ini appname.ini



I also have a setup script that does the following (potentially causing problems with duplicate logs?)

sudo ufw allow 'Nginx Full'

export FLASK_APP=appname.py
export APPNAME_SETTINGS=app_settings.cfg

sudo cp service/appname.service /etc/systemd/system/appname.service

sudo cp nginxServerBlock/appname /etc/nginx/sites-available/
sudo ln -s /etc/nginx/sites-available/appname /etc/nginx/sites-enabled
sudo nginx -t #this tests for syntax errors

sudo systemctl start appname
sudo systemctl enable appname

I changed the # of slashes after unix and before home (now etc, the dir was changed), among a bunch of other things I saw that were different in various guides.

I tried to move the socket by changing the location specified in the .ini file and in the server block, but the error is completely unchanged, so nginx seems to be looking for the socket in the same directory.

The directory nginx is searching for to find the socket is not in my configuration anywhere.

[UPDATE] I discovered that there are duplicate logs in the var/log/nginx directory, 8 copies of access.log and 8 copies of error.log. I have been running the setup script after each change (to move the files to the appropriate places after pulling the changes with git) and using daemon reload (I can't remember the exact name) as per the instructions that appear in terminal after running the setup script...could something in my script be causing the duplicates? Could it be possible that I've made some weird duplicate setup with different services by accident, each using a different pair of log files?

  • It was 3 slashes after unix every time, no matter what the number was I set in my server block file. I'm not sure what's going on. – Ajacmac Aug 30 '16 at 2:04
  • Try move socket outside home directory. – Federico Sierra Aug 30 '16 at 3:22
  • Add the ls -l /home/me/appname/appname/appname.sock output to the question. – drookie Aug 30 '16 at 5:16
  • And all parent directories. Sometimes home directory is not accessible to others. – Alexey Ten Aug 30 '16 at 5:34
  • find / -name appname.sock tells you where the socket actually exists. – Tero Kilkanen Aug 30 '16 at 9:57
ExecStart=/home/me/appnam/uwsgi --ini appname.ini

That looks like a typo (appnam).

Are you sure the server is running? Can you connect with socat?


How about modify as

uwsgi_pass unix:/home/me/appname/appname/appname.sock;
  • The last thing I tried was: ' uwsgi_pass unix:/etc/candidateClicker.sock; ' along with changing the appropriate line in the .ini to ' socket = /etc/candidateClicker.sock ' and it still didn't work. The error in the log also seems to be unchanged. – Ajacmac Sep 2 '16 at 1:10

ngnix runs as a seperate process, so before you start your application you need to stop the ngnix.

sudo service ngnix stop. Otherwise the socket myapp.socket will not be visible to the ngnix. Even though when you do ls /var/www/myapp/myapp.socket did show up in the terminal results for ls command. Because ngnix was started before you run your app using uwsgi myapp.ini command, ngnix's process doesn't know what that socket myapp.socket is . So the trick to avoid this issue is.

  1. Stop ngnix using sudo service ngnix stop
  2. Start your app uwsgi myapp.ini
  3. Start the ngnix sudo service ngnix start

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.