The Fool

Configurer un site web Django

Configuration pour Gunicorn (dans /var/www/<user>/django_site/<site>/conf/gunicorn.conf)

bind = "unix:/var/www/<user>/run/<site>.gunicorn.sock"
pidfile = "/var/www/<user>/run/<site>.gunicorn.pid"
daemon = False
debug = False
workers = 2
logfile = "/var/www/<user>/log/<site>.gunicorn.log"
loglevel = "info"

Configuration de Supervisord (dans /etc/supervisor/conf.d/<site>.conf)

[program:<site>]
command=gunicorn_django -c /var/www/<user>/django_site/<site>/conf/gunicorn.conf
directory=/var/www/<user>/django/<site>
user=<user>
group=<group>
autostart=true
autorestart=true
redirect_stderr=True

Redémarrer les processus de Supervisord

# invoke-rc.d supervisor stop
# invoke-rc.d supervisor start

Configuration de Nginx (dans /etc/nginx/site-available/<site>)

server {

        listen   80; ## listen for ipv4
        listen   [::]:80; ## listen for ipv6

        server_name <domain>;

        access_log  /var/log/nginx/<domain>.access.log;

        root            /var/www/<user>/<domain>/;

        location / {
                proxy_set_header X-Forwarded-For $proxy_add_x_forwarded_for;
                proxy_set_header Host $http_host;
                proxy_redirect off;
                if (!-f $request_filename) {
                        proxy_pass http://<site>_backend;
                        break;
                }
        }

        # deny access to .htaccess files, if Apache's document root
        # concurs with nginx's one

        location ~ /\.ht {
                deny  all;
        }
}

upstream <site>_backend {
        server unix:/var/www/<user>/run/<site>.gunicorn.sock;
}

Activer le site

# ln -s /etc/nginx/sites-available/<site> /etc/nginx/sites-enabled/

Recharger Nginx

# invoke-rc.d nginx reload