我正在尝试使用他们的教程how to setup django在数字海洋上部署django应用程序。像其他人一样,我也面临502错误。我看到没有生成myproject.sock文件。如何修复错误。
我的</center>
<footer class="footer">©2016 Garan Thomas - <a href="contact.html">Contact Me</a>.</footer>
/etc/systemd/system/gunicorn.service
nginx配置在[Unit]
Description=gunicorn daemon
After=network.target
[Service]
User=root
Group=www-data
WorkingDirectory=/home/root/myproject
ExecStart=/home/root/myproject/myprojectenv/bin/gunicorn --workers 3 --bind unix:/home/root/myproject/myproject.sock myproject.wsgi:application
[Install]
WantedBy=multi-user.target
/etc/nginx/sites-available/myproject
我在项目根文件夹
中找不到任何myproject.sock文件答案 0 :(得分:1)
nginx看起来不错但是对于.sock文件,我建议更改它并调用.sh文件: myproject.sock:
[Unit]
Description=Myproject gunicorn daemon
[Service]
Type=simple
User=root
ExecStart=/home/root/myproject_start.sh
[Install]
WantedBy=multi-user.target
myproject_start.sh
#!/bin/bash
NAME="myproject"
DJANGODIR=/home/root/myproject
SOCKFILE=/home/root/myproject/myproject.sock
USER=root
#GROUP=www-data
NUM_WORKERS=3
DJANGO_SETTINGS_MODULE=myproject.settings
DJANGO_WSGI_MODULE=myproject.wsgi
echo "Starting $NAME as `whoami`"
# Activate the virtual environment
cd $DJANGODIR
#IF YOU HAVE VIRTUALENV - OTHERWISE CHOOSE YOUR PYTHON DIR
source /home/root/myproject/myprojectenv/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
exec /home/root/myproject/myprojectenv/bin/gunicorn ${DJANGO_WSGI_MODULE}:application \
--name $NAME \
--workers $NUM_WORKERS \
--user $USER \
--bind=unix:$SOCKFILE