Django + Gunicorn + nginx内部服务器错误,错误在哪里以及如何解决?

时间:2014-04-09 20:21:02

标签: python django nginx gunicorn

所以我运行的是非常标准的设置,我按照之前的相同教程进行操作,但现在它的工作原因不明。

当我运行./manage.py runserver my_ip:8000时,它运行正常。 当我通过bin/gunicorn_start运行我的gunicorn脚本时,它工作正常并创建了sock文件 但是当我通过supervisor和nginx运行gunicorn脚本时,它会导致Internal Server Error,并且错误日志中没有信息。我究竟做错了什么?我想这是枪支或许可问题吗?

仓/ gunicorn_start

#!/bin/bash

NAME="today" # Name of the application
DJANGODIR=~/deployment/today_project/
SOCKFILE=~/deployment/run/gunicorn.sock # we will communicte using this unix socket
USER=ferski # the user to run as
GROUP=ferski # the group to run as
NUM_WORKERS=3 # how many worker processes should Gunicorn spawn
DJANGO_SETTINGS_MODULE=today_project.settings # which settings file should Django use
DJANGO_WSGI_MODULE=today_project.wsgi # 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 \
--log-level=debug \
--bind=unix:$SOCKFILE

/etc/supervisord.conf(只是未发送的文件)

[unix_http_server]
file=/tmp/supervisor.sock   ; (the path to the socket file)
...
[supervisorctl]
serverurl=unix:///tmp/supervisor.sock ; use a unix:// URL  for a unix socket
...
[program:today]
command = /home/ferski/deployment/bin/gunicorn_start
user = ferski
stdout_logfile = /home/ferski/deployment/logs/gunicorn_supervisor.log
redirect_stderr = true
...

最后是nginx.conf

upstream today_app_server {
        server unix:/home/ferski/deployment/run/gunicorn.sock fail_timeout=0;
}

server {
        listen 80;
        server_name haxelita.pl;

        client_max_body_size 4G;
        access_log /home/ferski/deployment/logs/nginx-access.log;
        error_log /home/ferski/deployment/logs/nginx-error.log;

        location /static/ {
                alias /home/ferski/deployment/today_project/today/static/;
        }

        location / {

                proxy_set_header X-Forwarded-For $proxy_add_x_forwarded_for;
                proxy_set_header Host $http_host;
                proxy_redirect off;

                if (!-f $request_filename) {
                        proxy_pass http://today_app_server;
                        break;
                }
        }

         # Error pages
        error_page 500 502 503 504 /500.html;
        location = /500.html {
                root /home/ferski/deployment/today_project/today/static/;
        }
}

这里有什么不对?这是许可问题吗?

2 个答案:

答案 0 :(得分:2)

这个问题让我感到困惑。但我想通了,我想我会发布它以备将来参考,因为这是google搜索此错误的最佳位置。

    uwsgi --socket /path/to/sock --chdir /path/to/django/project/ --module project_name.wsgi --chmod-socket=664

然后,您可以添加核心和处理器的数量,但附加此数据(将4更改为应用程序中的核心数量)。

    --master --processes 4 --async 4 --ugreen 

答案 1 :(得分:0)

您无法在使用主管启动的脚本中通过source激活virtualenv环境。在supervisord.conf中使用directory=/home/ferski/deployment/today_project/

请参阅Supervising virtualenv django app via supervisor