Z
Z
zkweb2015-08-27 15:29:45
Django
zkweb, 2015-08-27 15:29:45

How to automatically start Django on Nginx + Uwsgi?

Hello!
How to automatically launch a Django site after a server restart?
With this command, the site is fully working in conjunction with Nginx + Uwsgi,
uwsgi --ini project_app.ini
after rebooting the OS, the site does not start.
How to do it right. I read a lot of information, but this is how my site got up) you can see an example

Answer the question

In order to leave comments, you need to log in

1 answer(s)
B
BorisBurkov, 2015-08-27
@BorisBurkov

On Debian 8, I did this:
Nginx gets up by default after a reboot. Here are its configs: /etc/nginx/sites-available/mysite.conf and its symlink /etc/nginx/sites-enabled/mysite.conf:

upstream django {
    server unix:///tmp/mysite.sock;
}

server {
    listen  80;
    server_name mysite.me www.mysite.me;
    charset utf-8;

    client_max_body_size 75M;

    location /media {
        alias /srv/mysite/mysite/media;
    }

    location /static {
        alias /srv/mysite/static;
    }

    location / {
        uwsgi_pass django;
        include /etc/nginx/uwsgi_params;
    }
}

This nginx configuration serves static and media directly from /media and /static and talks to Upstream's django via the /tmp/mysite.sock unix-domain socket.
Now uwsgi. It is launched when rebooting from rc.local in emperor mode as user www-data:
In `rc.local` I just add the line:
In `/etc/uwsgi/sites-available` (and hyperlink to it in `/etc/uwsgi/sites-enabled`) mysite.ini file:
[uwsgi]
chdir = /srv/mysite
module = mysite.wsgi:application

plugin = python
# http = 0.0.0.0:8000 - use this to test uwsgi directly without nginx frontend
socket = /tmp/mysite.sock
chmod-socket = 664
vacuum = true

master = true
need-app = true
processes = 10
harakiri  = 20
max-requests = 5000

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question