【问题标题】:Django - Supervisor : exited too quicklyDjango - 主管:退出太快
【发布时间】:2018-04-13 23:22:23
【问题描述】:

我尝试在 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 的教程:我迷失了并且尝试了很多东西。 有人可以给我一个简单快速的教程来部署他用来满足他的需求吗?

谢谢!

【问题讨论】:

    标签: python django nginx


    【解决方案1】:

    问题是您的配置文件中缺少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

    【讨论】:

    • 不错。应用程序启动,但我仍然收到“欢迎使用 NGINX”。
    • 好像你有默认的配置服务。查找文件 /etc/nginx/conf.d/default.conf/etc/nginx/sites-enabled/default。删除默认配置文件,然后重新启动 nginx。它应该工作
    • 尝试将--bind mywebsite.fr:8002更改为--bind 127.0.0.1:8002
    • netstat -plant 的输出是什么?还有supervisor tail sitepro?
    • Tarun 发现我的问题:我忘记在站点可用和启用站点之间设置符号链接 headdesk
    【解决方案2】:

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

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

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

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

    重启管理员

    supervisorctl restart sitepro
    

    重新启动后,转到日志并告诉我们您看到了什么。

    【讨论】:

    • 好主意!我在下面的评论中看到了与 Tarun Lalwani 相同的错误。
    【解决方案3】:

    在我的 .conf(主管)文件中:

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

    仔细检查目录路径:(/home/user/sitepro/bin/gunicorn sitepro.wsgi:application)

    您可能输入了路径错误

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 2022-06-20
      • 1970-01-01
      • 1970-01-01
      • 2011-06-08
      • 2014-06-24
      相关资源
      最近更新 更多