Django - 主管:退出太快

时间:2017-11-01 15:28:51

标签: python django nginx

我尝试在Ubuntu服务器16.04上的Django + Supervisor + NGINX中部署我的网站。

这是我的.conf(主管):

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

我的NGINX配置文件:

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;
    }
}

当我尝试在项目的根目录上启动gunicorn时,一切顺利:

(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

我已经完成了supervisorctrl重读和更新(工作)。 如果我做supervisorctl status sitepro

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

如果我访问我的网站,我就会收到“欢迎使用Nginx”默认页面。

我已经尝试了许多用于部署django的教程:我迷失了并尝试了很多东西。 有人可以给我一个简单快速的教程来部署他用于他的propre needings的Django吗?

谢谢!

2 个答案:

答案 0 :(得分:6)

问题是您错过了配置文件中的directory=...

[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

否则gunicorn将不知道在哪里找到sitepro.wsgi:application

答案 1 :(得分:3)

要查看发生了什么,您应该记录主管输出。

为此,请打开supervisor .conf文件,并添加以下行:

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

可能的{Path}可能是/ home / {youruser} /sitepro.log

重启主管

supervisorctl restart sitepro

重新启动后,转到日志并告诉我们您的所见。

相关问题