Search code examples
djangoubuntunginxuwsgidigital-ocean

uWSGI config error 'core/socket.c' - w/ Django & NGINX


I'm setting up a Django site on Ubuntu 14.04 (Digital Ocean Droplet) using NGINX & uWSGI (following this tutorial w/ out making a second project). I can run my Django site with manage.py. I can also run uwsgi --http :8080 --home /home/andrew/Env/personalsitevenv --chdir /home/andrew/andrew-django-personal-site/personalsite -w personalsite.wsgi without any issues. I can see my site running at my IP:Port. I can also run uwsgi --http :8000 --module personalsite.wsgi --virtualenv /home/andrew/Env/personalsitevenv without issue.

When I go to my server's IP all I see is the Welcome to nginx! page. There aren't any NGINX log errors & sudo service nginx configtest is clean. The only information I'm getting is in my log file that I set up for uWSGI which contains:

*** Starting uWSGI 2.0.12 (64bit) on [Fri Jul  8 00:41:22 2016] ***
compiled with version: 4.8.4 on 05 July 2016 17:45:39
os: Linux-4.4.0-28-generic #47~14.04.1-Ubuntu SMP Fri Jun 24 16:30:35 UTC 2016
nodename: **********
machine: x86_64
clock source: unix
pcre jit disabled
detected number of CPU cores: 1
current working directory: /etc/uwsgi/sites
detected binary path: /usr/local/bin/uwsgi
chdir() to /home/andrew/andrew-django-personal-site/personalsite
your processes number limit is 1832
your memory page size is 4096 bytes
detected max file descriptor number: 1024
lock engine: pthread robust mutexes
thunder lock: disabled (you can enable it with --thunder-lock)
bind(): No such file or directory [core/socket.c line 230]

Can anyone spot any configuration issues or anything else that might be wrong here?


/etc/uwsgi/sites/personalsite.ini

[uwsgi]
logto = /var/log/uwsgi/log.txt

project = personalsite
base = /home/andrew
repo = andrew-django-personal-site

chdir = %(base)/%(repo)/%(project)
home = %(base)/Env/personalsitevenv
module = %(project).wsgi:application

master = true
processes = 5

socket = $(base)/%(repo)/%(project)/%(project).sock
chmod-socket = 664
chown-socket = www-data
vacuum = true

/etc/init/uwsgi.conf

description "uWSGI application server in Emperor mode"

start on runlevel [2345]
stop on runlevel [!2345]

setuid andrew
setgid www-data

exec /usr/local/bin/uwsgi --emperor /etc/uwsgi/sites

/etc/nginx/sites-available/personalsite

server {
    listen 80;

    location = /favicon.ico { access_log off; log_not_found off; }
    location /static/ {
        root /home/andrew/andrew-django-personal-site/personalsite;
    }

    location / {
        include         uwsgi_params;
        uwsgi_pass      unix:/home/andrew/andrew-django-personal-site/personalsite/personalsite.sock;
    }
}

Solution

  • It appears that the personalsite.ini file contains socket path as a pattern which might have 0 or more matches, that might not match the real path, so updating it to the absolute path will resolve the problem.

    in your personalsite.ini: if you replace

    socket = $(base)/%(repo)/%(project)/%(project).sock
    

    with the absolute path of your socket's location

    socket = /home/andrew/andrew-django-personal-site/personalsite/personalsite.sock
    

    this will solve the problem.

    Once you know the socket location you can design a pattern that will match it.

    Sample location in nginx config:

    location / {
        uwsgi_pass unix:/home/andrew/andrew-django-personal-site/personalsite/personalsite.sock;
        include /your_location/conf/uwsgi_params; // or your own
        uwsgi_modifier1 30;          // ignore extra if not used
        proxy_set_header HTTP_AUTHORIZATION $http_authorization; // only use if needed
        proxy_set_header  X-Real-IP  $remote_addr; // only use if needed
        proxy_set_header  X-Forwarded-For $proxy_add_x_forwarded_for;// only if needed
        proxy_set_header  Host $http_host; // only use if needed
        proxy_redirect  off;  // only use if needed
    }