DEV Community

Hasanul Islam
Hasanul Islam

Posted on • Edited on

4 2

uwsgi error: bind(): No such file or directory [core/socket.c line 230]

Problem:

Sometimes, sites running on uwsgi and nginx cannot find socket file due to suddent restart of server. The most common error from /var/log/nginx/error.log in this case is:

bind(): No such file or directory [core/socket.c line 230]
Enter fullscreen mode Exit fullscreen mode

Content of Nginx config file:

Support, content of /etc/nginx/sites-enabled/demo_app.ini is:

server {
    listen 80;
    server_name www.example.com;
    return 301 https://example.com$request_uri;
}

server {

    listen 80 default_server;
    server_name example.com;

    location = /favicon.ico { access_log off; log_not_found off; }

    location /static/ {
        alias /home/ubuntu/app/demo_app/static/;
            autoindex off;

            location ~* \.(eot|ttf|woff|woff2)$ {
            add_header 'Access-Control-Allow-Origin' '*';
        }
    }

    location /media/ {
        alias /home/ubuntu/app/demo_app/media/;
        autoindex off;
    }

    location / {
        add_header 'Access-Control-Allow-Origin' '*';

        include         uwsgi_params;
        uwsgi_pass      unix:/var/run/uwsgi/demo_app.sock;
    }
}
Enter fullscreen mode Exit fullscreen mode

Content of uwsgi config file:

And, content of etc/uwsgi/sites/demo_app.ini file is:

project = demo_app
base    = /home/ubuntu/app

chdir   = %(base)/%(project)
home    = %(base)/venv
module  = conf.wsgi:application
env     = DJANGO_SETTINGS_MODULE=conf.settings

master  = true
processes = 5

socket = /var/run/uwsgi/%(project).sock
chmod-socket = 777
uid     = www-data
gid     = www-data

harakiri = 60
vacuum  = true
buffer-size = 32768

logger = file:/tmp/uwsgi.log
log-maxsize = 200000
Enter fullscreen mode Exit fullscreen mode

Solution:

After a reboot socket file inside /var/run/uwsgi/ gets lost, because no folder exists with name uwsgi. That's why this folder is needed to be created.

mkdir /var/run/uwsgi
Enter fullscreen mode Exit fullscreen mode

and

sudo chown -R www-data:www-data /var/run/uwsgi
Enter fullscreen mode Exit fullscreen mode

Reference:
https://stackoverflow.com/questions/27791330/bind-no-such-file-or-directory-core-socket-c-line-230

Image of Datadog

The Essential Toolkit for Front-end Developers

Take a user-centric approach to front-end monitoring that evolves alongside increasingly complex frameworks and single-page applications.

Get The Kit

Top comments (0)

Postmark Image

Speedy emails, satisfied customers

Are delayed transactional emails costing you user satisfaction? Postmark delivers your emails almost instantly, keeping your customers happy and connected.

Sign up