我已经设置了一个应用程序,可以在nginx上运行gunicorn。这是我的gunicorn的设置:
#!/bin/bash
NAME="davidbien"
DJANGODIR=/home/ec2-user/davidbien
SOCKFILE=/home/ec2-user/davidbien/davidbien.sock
USER=ec2-user
GROUP=ec2-user
NUM_WORKERS=3
DJANGO_SETTINGS_MODULE=davidbien.settings
DJANGO_WSGI_MODULE=davidbien.wsgi
echo "Starting $NAME as `whoami`"
# Activate the virtual environment
cd $DJANGODIR
source ../virtual/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
exec gunicorn ${DJANGO_WSGI_MODULE}:application \
--name $NAME \
--workers $NUM_WORKERS \
--user=$USER --group=$GROUP \
--bind=unix:$SOCKFILE \
--log-level=debug \
--log-file=-
这是我的nginx设置:
upstream app_server_djangoapp {
server unix:/home/ec2-user/davidbien/davidbien.sock fail_timeout=0;
}
server {
listen 80;
server_name ;
access_log /var/log/nginx/guni-access.log;
error_log /var/log/nginx/guni-error.log info;
keepalive_timeout 52.56.193.57;
# path for static files
root /home/ec2-user/davidbien/davidbien/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://app_server_djangoapp;
break;
}
}
}
运行nginx时,我在日志中不断收到以下错误:
[crit] 23465#0: *1 connect() to unix:/home/ec2-user/davidbien/davidbien.sock failed (13: Permission denied) while connecting to upstream, client: 2.96.149.96, server: 52.56.193.57, request: "GET /faviconn.ico HTTP/1.1", upstream: "http://unix:/home/ec2-user/davidbien/davidbieen.sock:/favicon.ico", host: "52.56.193.57", referrer: "http://52.56.193.57/"
这有什么问题?我相信我使用的用户是其目录中文件夹的所有者。