Gunicorn-Supervisor Django 设置问题



我正在尝试设置一个 DigitalOcean Droplet 来容纳一个 Django 应用程序,我遵循以下概述:https://simpleisbetterthancomplex.com/tutorial/2016/10/14/how-to-deploy-to-digital-ocean.html

当我通过以下方式执行它时,应用程序运行良好:python manage.py runserver 0.0.0.0:8000

但是,一旦通过sudo supervisorctl restart all启动应用程序并且我运行sudo supervisorctl status,我就会得到这个,但是当我到达正确的URL时,该应用程序不起作用:

site@SiteDroplet:~$  sudo supervisorctl status Site
Site                      RUNNING   pid 3071, uptime 0:00:19

有人可以帮忙吗?

这是我的目录结构:

site@SiteDroplet:~$ cd ../
site@SiteDroplet:/home$ cd ../
site@SiteDroplet:/$ ls
bin   dev  home        initrd.img.old  lib64       media  opt   root  sbin  srv  tmp  var      vmlinuz.old
boot  etc  initrd.img  lib             lost+found  mnt    proc  run   snap  sys  usr  vmlinuz
site@SiteDroplet:/$ ^C
site@SiteDroplet:/$ cd home
site@SiteDroplet:/home$ ls
site
site@SiteDroplet:/home$ cd site
site@SiteDroplet:~$ ls
Site  bin  include  lib  local  logs  run  share
site@SiteDroplet:~$ cd bin
site@SiteDroplet:~/bin$ ls
activate      activate.fish     easy_install      gunicorn_start  pip2    python         python2    wheel
activate.csh  activate_this.py  easy_install-2.7  pip             pip2.7  python-config  python2.7
site@SiteDroplet:~/bin$ cd ../
site@SiteDroplet:~$ cd Site
site@SiteDroplet:~/Site$ ls
Site  app.yaml   forms            interface_login        interface_management  interface_resident  interface_security  objects         requirements.txt  utils
README.md    cron.yaml  interface_admin  interface_maintenance  interface_onsite      interface_root      manage.py           objects_client  templates
site@SiteDroplet:~/Site$ Site is my Django Project Directory

这是我gunicorn_start文件

#!/bin/bash
NAME="Site"
DIR=/home/site/Site
USER=site
GROUP=site
WORKERS=3
BIND=unix:/home/site/run/gunicorn.sock
DJANGO_SETTINGS_MODULE=Site.settings
DJANGO_WSGI_MODULE=Site.wsgi
LOG_LEVEL=error
cd $DIR
source ../bin/activate
export DJANGO_SETTINGS_MODULE=$DJANGO_SETTINGS_MODULE
export PYTHONPATH=$DIR:$PYTHONPATH

exec ../bin/gunicorn_start ${DJANGO_WSGI_MODULE}:application 
--name $NAME 
--workers $WORKERS 
--user=$USER 
--group=$GROUP 
--bind=$BIND 
--log-level=$LOG_LEVEL 
--log-file=-

这是我的主管配置

[program:Site]
command=/home/site/bin/gunicorn_start
user=site
autostart=true
autorestart=true
redirect_stderr=true
stdout_logfile=/home/site/logs/gunicorn-error.log

Nginix config

upstream app_server {
server unix:/home/site/run/gunicorn.sock fail_timeout=0;
}
server {
listen 80;
# add here the ip address of your server
# or a domain pointing to that ip (like example.com or www.example.com)
server_name 157.230.230.54;
keepalive_timeout 5;
client_max_body_size 4G;
access_log /home/site/logs/nginx-access.log;
error_log /home/site/logs/nginx-error.log;
location /static/ {
alias /home/site/static/;
}
# checks for static file, if not found proxy to app
location / {
try_files $uri @proxy_to_app;
}
location @proxy_to_app {
proxy_set_header X-Forwarded-For $proxy_add_x_forwarded_for;
proxy_set_header Host $http_host;
proxy_redirect off;
proxy_pass http://app_server;
}
}

最新的枪角兽错误.log

/home/site/Site/../bin/gunicorn_start: line 16: 
/home/site/Site/../bin/gunicorn_start: Argument list too long
/home/site/Site/../bin/gunicorn_start: line 16: / 
/home/site/Site/../bin/gunicorn_start: Success

我不知道你为什么有这么复杂的设置,这是我的帐户网站 conf,就像一个魅力:

[group:accounting]
programs=accounting_web
[program:accounting_web]
command = /home/web/.virtualenvs/accounting/bin/gunicorn accounting.wsgi --workers=1 --threads=4 -b unix:/tmp/gunicorn_accounting.sock --log-level=DEBUG --timeout=120
directory = /home/web/accounting
user = web
environment=PATH="/home/web/.virtualenvs/accounting/bin"

可能是gunicorn_start脚本有语法错误。我的建议是直接在主管 .conf 上使用较小的命令行。

在nginx.conf上:

1) 尝试使用有效的 URL 更改服务器名称参数,例如:

exactestate.com

2) 将袜子配置更改为 TCP:

upstream gunicorn_panel {
# For a TCP configuration:
server 127.0.0.1:9000 fail_timeout=0; }
server {
listen 8080;

在supervisor.conf 上,尝试直接在命令变量上编写所有命令,而不是使用 gunicorn_start 文件:

[program:powerpanel]
command=/home/web/.virtualenvs/accounting/bin/gunicorn powerpanel.wsgi -b 127.0.0.1:9000 -w1 --pythonpath=/home/exactestate/ExactEstate --error-logfile=/home/exactestate/logs/gunicorn-error.log
user=webapp
autostart=true
autorestart=unexpected
startsecs=1
startretries=3
redirect_stderr=true

最新更新