12
votes

I try to deploy my website in Django+Supervisor+NGINX on Ubuntu server 16.04.

Here is my .conf (supervisor):

[program:sitepro]
command = /home/user/sitepro/bin/gunicorn sitepro.wsgi:application --bind mywebsite.fr:8002
user = user
autostart = true
autorestart = true

My NGINX config file :

server {
    listen      80;
    server_name .mywebsite.fr;
    charset     utf-8;
    root /home/user/sitepro/site/sitepro;
    access_log /home/user/sitepro/site/logs/nginx/access.log;
    error_log /home/user/sitepro/site/logs/nginx/error.log;

    location /static {
        alias /home/user/sitepro/site/static;
    }

    location / {
        proxy_set_header Host $http_host;
        proxy_set_header X-Forwarded-For $proxy_add_x_forwarded_for;
        proxy_redirect off;
        proxy_pass http://127.0.0.1:8002;
    }
}

When I try to launch gunicorn on the root of my project, everything goes right :

(sitepro) user@mybps:~/sitepro/site$ gunicorn sitepro.wsgi:application --bind mywebsite.fr:8002
[2017-11-01 16:09:37 +0000] [1920] [INFO] Starting gunicorn 19.7.1
[2017-11-01 16:09:37 +0000] [1920] [INFO] Listening at: http://79.137.39.12:8002 (1920)
[2017-11-01 16:09:37 +0000] [1920] [INFO] Using worker: sync
[2017-11-01 16:09:37 +0000] [1925] [INFO] Booting worker with pid: 1925

I've done a supervisorctrl reread and update (worked). And if I make supervisorctl status sitepro

sitepro                          FATAL     Exited too quickly (process log may have details)

And if I access my website I've got the "Welcome to Nginx" default page.

I've tried many tutorials for deploy django : I'm lost and tried many things. Could someone give me a simple and fast tutorial to deploy Django that he used for his propre needings please ?

Thanks !

3

3 Answers

11
votes

The issue is that you are missing the directory=... in your config file

[program:sitepro]
command = /home/user/sitepro/bin/gunicorn sitepro.wsgi:application --bind mywebsite.fr:8002
directory = /home/user/sitepro/site
user = user
autostart = true
autorestart = true

Otherwise gunicorn will not know where to find sitepro.wsgi:application

5
votes

To see what is going on, you should log the supervisor output.

To do that, open the supervisor .conf file, and add the following lines:

stdout_logfile={Path}
stderr_logfile={Path}
autostart=true
autorestart=true
startsecs=10

A possible {Path} could be /home/{youruser}/sitepro.log

Restart supervisor

supervisorctl restart sitepro

Once restarted, go to the log and tell us what you see.

0
votes

in my .conf (supervisor) file:

command = /home/user/sitepro/bin/gunicorn sitepro.wsgi:application --bind mywebsite.fr:8002

Double-check the directory path: (/home/user/sitepro/bin/gunicorn sitepro.wsgi:application)

You may have inputted the incorrectly path