Python - uWSGI Configuration

pip install uwsgi

uwsgi –http :8000 –wsgi-file test.py
uwsgi –http :8000 –module mysite.wsgi

uwsgi –socket :8000 –module mysite.wsgi
uwsgi –socket /var/run/uwsgi/mysite.sock –module mysite.wsgi –chmod-socket=666

uwsgi –ini /etc/uwsgi/vassals/mysite.ini
uwsgi –emperor /etc/uwsgi/vassals

Edit /etc/rc.local to let it run when OS start up.

Collect static files for django:
1. update STATIC_ROOT in mysite/settings.py
2.

python manage.py collectstatic

mysite.ini

[uwsgi]

chdir  = /root/test/uwsgi-tutorial/demo-django/mysite # /path/to/your/django/project (full path)
module = mysite.wsgi # django wsgi module, module = mysite.wsgi:application
home = /root/test/uwsgi-tutorial # the virtualenv (full path)

master = true
processes = 3
socket = /var/run/uwsgi/mysite.sock # /path/to/your/project/mysite.sock (full path)
chmod-socket = 666
vaccum = true
daemonize = /var/log/uwsgi/yourproject.log
#max-requests = 5000 # respawn processes after serving 5000 requests
#harakiri = 20 # respawn processes taking more than 20 seconds
#limit-as = 128 # limit the project to 128 MB
#pidfile = /tmp/project-master.pid

nginx.conf

http {
    include       mime.types;
    default_type  application/octet-stream;
    sendfile        on;
    keepalive_timeout  65;

    upstream django {
         #server 127.0.0.1:8001;
         server unix:///var/run/uwsgi/mysite.sock;
    }
   
    server {
        listen 8000;
        charset utf-8;
        #client_max_body_size 75M;
        location /static {
            alias /tmp/mysite_static;
        }
        location / {
            uwsgi_pass django;
            include uwsgi_params;
        }
    }
}

uwsgi-restart script

ps aux | grep uwsgi
killall -9 -e 'uwsgi'
uwsgi --emperor /etc/uwsgi/vassals &
sleep 3s
ps aux | grep uwsgi