Nginx cannot see unix socket

9,601
User=me
Group=www-data
WorkingDirectory=/home/me/appname
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?

Share:
9,601

Related videos on Youtube

Ajacmac
Author by

Ajacmac

Updated on September 18, 2022

Comments

  • Ajacmac
    Ajacmac over 1 year

    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...

    https://www.digitalocean.com/community/tutorials/how-to-serve-flask-applications-with-uwsgi-and-nginx-on-ubuntu-16-04

    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...

    [uwsgi]
    
    module:wsgi:app
    
    master = true
    processes = 5
    
    socket = /etc/appname.sock
    chmod-socket = 660
    vacuum = true
    
    die-on-term = true
    

    my .service file looks like this...

    [Unit]
    
    Description=UWSGI instance to serve app
    After=network.target
    
    
    [Service]
    
    User=me
    Group=www-data
    WorkingDirectory=/home/me/appname
    ExecStart=/home/me/appnam/uwsgi --ini appname.ini
    
    
    [Install]
    
    WantedBy=multi-user.target
    

    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?

    • Admin
      Admin over 7 years
      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.
    • Admin
      Admin over 7 years
      Try move socket outside home directory.
    • Admin
      Admin over 7 years
      Add the ls -l /home/me/appname/appname/appname.sock output to the question.
    • Admin
      Admin over 7 years
      And all parent directories. Sometimes home directory is not accessible to others.
    • Admin
      Admin over 7 years
      find / -name appname.sock tells you where the socket actually exists.
    • Admin
      Admin over 7 years
      I'm moving the socket outside /home, and if that doesn't help I'll try the other suggestions. Does anyone know why this was downvoted? This site honestly confuses me so much sometimes, and I can't even get my reputation high enough to ask what's what in chat.
    • Admin
      Admin over 7 years
      @TeroKilkanen I tried that and just got a longlist of "Permission denied" 's, even when using sudo, the app wasn't running at the time though. I've never tried running multiple simultaneous secure shells, but do I need to have one going to run the server and another to do the search?
    • Admin
      Admin over 7 years
      It depends on if you have set it up to run as a service. You should install it anyway as a service, then you can use standard service tools to start / stop it. You don't need to leave a shell running after starting a service.
  • Ajacmac
    Ajacmac over 7 years
    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.
  • Kef Schecter
    Kef Schecter over 2 years
    This makes no sense to me. Why would the process be unable to see the socket just because the socket didn't exist when the process started? I don't think it even looks for the socket until it receives a request that uses it.