我正在使用Gunicorn作为应用服务器和Nginx作为Web服务器部署Django项目。这是我正在关注的教程http://tutos.readthedocs.io/en/latest/source/ndg.html。 gunicorn_start.sh的代码(保存在项目所在的文件夹中)。
#!/bin/bash
NAME="visualization"
DJANGODIR=/var/www/dist/adc # Django project directory*
SOCKFILE=/var/www/dist/run/gunicorn.sock
USER=barun
GROUP=barun
NUM_WORKERS=1
DJANGO_SETTINGS_MODULE=adc.settings
DJANGO_WSGI_MODULE=adc.wsgi
echo "Starting $NAME as `whoami`"
# Activate the virtual environment
cd $DJANGODIR
source /home/barun/anaconda3/envs/adcenv/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
exec /home/barun/anaconda3/envs/adcenv/bin/gunicorn
${DJANGO_WSGI_MODULE}:application \ #we should put the address
gunicorn address
--name $NAME \
--workers $NUM_WORKERS \
--user $USER \
--bind=unix:$SOCKFILE
gunicorn.service的代码(/lib/systemd/system/gunicorn.service):
[Unit]
Description=visualization gunicorn daemon
[Service]
Type=simple
User=barun
WorkingDirectory=/var/www/dist
ExecStart=/home/barun/anaconda3/envs/adcenv/bin/gunicorn --workers 3 --
bind unix:/var/www/dist/run/gunicorn.sock adc.wsgi:application
[Install]
WantedBy=multi-user.target
一切都很好。该位置在gunicorn_start.sh文件中给出,用于创建套接字文件,运行文件夹已创建,但gunicorn.sock文件未创建。没有许可相关问题
除此之外,我在Nginx error.log文件中得到的错误是:
4783#4783: *1 connect() to unix:/var/www/dist/run/gunicorn.sock failed (2: No such file or directory) while connecting to upstream, client: 172.16.1.213, server: 192.16.1.213, request: "GET / HTTP/1.1", upstream: "http://unix:/var/www/dist/run/gunicorn.sock:/", host: "172.16.1.213:8080"
当我执行./gunicorn_start.sh时,应该创建套接字文件但不会发生。
答案 0 :(得分:1)
解决!
我做了一切都是新鲜的。卸载并再次安装Gunicorn和Nginx。删除所有配置文件并再次写入。 现在它运作良好。