过去几天,我一直在尝试解决此问题。因此,非常感谢您的帮助。我有一个与ubuntu服务器18.04一起安装的VPS,并且正在尝试使用主管,gunicorn和nginx部署django应用程序。我是该平台的新手,因此请紧跟本教程。 https://jee-appy.blogspot.com/2017/01/deply-django-with-nginx.html
我在服务器上的设置是唯一的用户“ root”。
Django:2.1.4
nginx:nginx / 1.14.0(Ubuntu)
gunicorn :(版本19.9.0)
geteat.conf(/ etc / nginx / sites-available)
upstream geteatapp_server {
server unix:/root/djangoproject/geteat_dir/geteat_venv/run/gunicorn.sock fail_timeout=0;
}
server {
listen 80;
server_name 26.208.54.108;
client_max_body_size 4G;
access_log /root/djangoproject/logs/nginx-access.log;
error_log /root/djangoproject/logs/nginx-error.log;
location /static/ {
root /root/djangoproject/geteat_dir/geteat/;
}
location /media/ {
root /root/djangoproject/geteat_dir/geteat/;
}
location / {
# an HTTP header important enough to have its own Wikipedia entry:
# http://en.wikipedia.org/wiki/X-Forwarded-For
proxy_set_header X-Forwarded-For $proxy_add_x_forwarded_for;
# proxy_set_header Host $http_host;
proxy_set_header Host $host;
proxy_redirect off;
if (!-f $request_filename) {
proxy_pass http://geteatapp_server;
break;
}
}
# Error pages
error_page 500 502 503 504 /500.html;
location = /500.html {
root /root/djangoproject/geteat_dir/geteat/static/;
}
}
gunicorn_start.bash(在项目根目录)
#!/bin/bash
NAME="geteatapp" # Name of the application
DJANGODIR=~/djangoproject/geteat_dir/geteat/ # Django project directory
SOCKFILE=~/djangoproject/geteat_dir/geteat_venv/run/gunicorn.sock # we will communicte using this unix socket
USER=root # the user to run as
GROUP=root # the group to run as
NUM_WORKERS=3 # how many worker processes should Gunicorn spawn
DJANGO_SETTINGS_MODULE=geteat.settings # which settings file should Django use
DJANGO_WSGI_MODULE=geteat.wsgi # WSGI module name
echo "Starting $NAME as `whoami`"
# Activate the virtual environment
cd $DJANGODIR
source ~/djangoproject/geteat_dir/geteat_venv/bin/activate
export DJANGO_SETTINGS_MODULE=$DJANGO_SETTINGS_MODULE
export PYTHONPATH=$DJANGODIR:$PYTHONPATH
RUNDIR=$(dirname $SOCKFILE)
test -d $RUNDIR || mkdir -p $RUNDIR
# Start your Django Unicorn
exec gunicorn ${DJANGO_WSGI_MODULE}:application \
--name $NAME \
--workers $NUM_WORKERS \
--user=$USER --group=$GROUP \
--bind=unix:$SOCKFILE \
--log-level=debug \
--log-file=-
nginx-error.log中的最后4行
2018/12/30 22:49:20 [crit] 3828#3828: *18 connect() to unix:/root/djangoproject/geteat_dir/geteat_venv/run/gunicorn.sock failed (13: Permission denied) while connecting to upstream, client: 177.128.60.213, server: 26.208.54.108, request: "GET / HTTP/1.1", upstream: "http://unix:/root/djangoproject/geteat_dir/geteat_venv/run/gunicorn.sock:/", host: "26.208.54.108:80"
2018/12/30 22:49:20 [error] 3828#3828: *18 open() "/root/djangoproject/geteat_dir/geteat/static/500.html" failed (13: Permission denied), client: 177.128.60.213, server: 26.208.54.108, request: "GET / HTTP/1.1", upstream: "http://unix:/root/djangoproject/geteat_dir/geteat_venv/run/gunicorn.sock/", host: "26.208.54.108:80"
2018/12/30 22:53:44 [crit] 3828#3828: *20 connect() to unix:/root/djangoproject/geteat_dir/geteat_venv/run/gunicorn.sock failed (13: Permission denied) while connecting to upstream, client: 54.197.21.132, server: 26.208.54.108, request: "GET / HTTP/1.1", upstream: "http://unix:/root/djangoproject/geteat_dir/geteat_venv/run/gunicorn.sock:/", host: "26.208.54.108"
2018/12/30 22:53:44 [error] 3828#3828: *20 open() "/root/djangoproject/geteat_dir/geteat/static/500.html" failed (13: Permission denied), client: 54.197.21.132, server: 26.208.54.108, request: "GET / HTTP/1.1", upstream: "http://unix:/root/djangoproject/geteat_dir/geteat_venv/run/gunicorn.sock/", host: "26.208.54.108"
主管的配置文件
[program:geteat]
command = /root/djangoproject/geteat_dir/geteat/gunicorn_start.bash ; Command to start app
user = root ; User to run as
stdout_logfile = ~/djangoproject/logs/gunicorn_supervisor.log ; Where to write log messages
redirect_stderr = true ; Save stderr in the same log
environment=LANG=en_US.UTF-8,LC_ALL=en_US.UTF-8 ; Set UTF-8 as default encoding