Gunicorn多站点托管设置

时间:2016-03-16 03:55:15

标签: linux django gunicorn

我很难在虚拟环境中执行gunicorn,以下是我的设置,因为我正在获取文件夹的Linux访问错误。我是Linux新手所以请指教。错误可以在以下设置中看到:

#!/bin/bash

NAME="myproject"                                                # Name of the application
DJANGODIR=/django/myproject                                         # Django project directory
SOCKFILE=/django/run/gunicorn.sock                              # we will communicte using this unix socket
USER=django                                                     # the user to run as
GROUP=django                                                    # the group to run as
NUM_WORKERS=3                                                   # how many worker processes should Gunicorn spawn
DJANGO_SETTINGS_MODULE=myproject.settings                       # which settings file should Django use
DJANGO_WSGI_MODULE=myproject.wsgi:application                    # WSGI module name

echo "Starting $NAME as `whoami`"

# Activate the virtual environment
cd $DJANGODIR
source ../bin/activate
export DJANGO_SETTINGS_MODULE=$DJANGO_SETTINGS_MODULE
export PYTHONPATH=$DJANGODIR:$PYTHONPATH

# Create the run directory if it doesn't exist
RUNDIR=$(dirname $SOCKFILE)
test -d $RUNDIR || mkdir -p $RUNDIR

# Start your Django Unicorn
# Programs meant to be run under supervisor should not daemonize themselves (do not use --daemon)
exec ../bin/gunicorn ${DJANGO_WSGI_MODULE}:application \
  --name $NAME \
  --workers $NUM_WORKERS \
  --user=$USER --group=$GROUP \
  --bind=unix:$SOCKFILE \
  --log-level=debug \
  --log-file=-

错误:

(myproject)django@vps:~/myproject$ bin/gunicorn_start.sh
Starting: command not found
(myproject)django@vps:~/myproject$ bin/gunicorn_start.sh: line 15: cd: /django/myproject: No such file or directory
-su: bin/gunicorn_start.sh:: No such file or directory
(myproject)django@vps:~/myproject$ bin/gunicorn_start.sh: line 16: ../bin/activate: No such file or directory
-su: bin/gunicorn_start.sh:: No such file or directory
(myproject)django@vps:~/myproject$ mkdir: cannot create directory ‘/django’: Permission denied
No command 'mkdir:' found, did you mean:
 Command 'mkdir' from package 'coreutils' (main)
mkdir:: command not found
(myproject)django@vps:~/myproject$ bin/gunicorn_start.sh: line 26: /home/django/myproject/../bin/gunicorn: No such file or directory

我正在关注link配置启动脚本,并且我创建了一个用户“django”。

在我将“DJANGODIR”更改为/ home / Django / myproject后,我现在收到了这两个错误。

(myproject)django@vps:~/myproject$ bin/gunicorn_start.sh
Starting myproject as django
bin/gunicorn_start.sh: line 16: ../bin/activate: No such file or directory
mkdir: cannot create directory ‘/django’: Permission denied
bin/gunicorn_start.sh: line 26: /home/django/myproject/../bin/gunicorn: No such file or directory
(myproject)django@vps:~/myproject$

我已经将gunicorn upstart脚本中的4行改为完整路径,如:

DJANGODIR=/home/django/myproject
SOCKFILE=/home/django/myproject/run/gunicorn.sock
source /home/django/myproject/bin/activate
exec /home/django/myproject/bin/gunicorn ${DJANGO_WSGI_MODULE}:application \

有一个额外的“应用程序”参数,我得到了错误。我已经删除了上面第四行中的应用程序,并且我能够运行该脚本。现在gunicorn正在运行,但由于myproject.com没有显示,我无法让项目生效。如何在此脚本中绑定端口?

1 个答案:

答案 0 :(得分:0)

我即将给你的答案是基于一个假设,我认为你的$DJANGODIR应该是/home/django/myproject,但你指的是/django/myproject属于ls -l filename root,这就是你的程序无法创建文件夹的原因。

如果我的假设不正确,请发布您的文件所在位置及其权限。您可以使用ls -ld directory获取文件的权限,使用AJAX - POST at 'data:' - Uncaught error- unexpected identifier 获取目录的权限。

希望这有帮助!