DEV Community

Hasanul Islam
Hasanul Islam

Posted on • Updated on

 

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

Top comments (0)

An Animated Guide to Node.js Event Loop

Node.js doesn’t stop from running other operations because of Libuv, a C++ library responsible for the event loop and asynchronously handling tasks such as network requests, DNS resolution, file system operations, data encryption, etc.

What happens under the hood when Node.js works on tasks such as database queries? We will explore it by following this piece of code step by step.