我遵循了本教程:http://michal.karzynski.pl/blog/2013/06/09/django-nginx-gunicorn-virtualenv-supervisor/
我的目录结构完全相同:
-rw-r--r-- 1 django webapps 0 Nov 30 15:58 access.log
drwxr-xr-x 3 django webapps 4096 Nov 30 17:27 bin
-rw-r--r-- 1 django webapps 6450 Nov 30 15:58 error.log
drwxr-xr-x 2 django webapps 4096 Nov 30 15:58 gunicorn
drwxr-xr-x 2 django webapps 4096 Nov 30 16:10 include
drwxr-xr-x 3 django webapps 4096 Nov 30 16:10 lib
lrwxrwxrwx 1 django webapps 3 Nov 30 16:10 lib64 -> lib
drwxr-xr-x 2 django webapps 4096 Nov 30 17:12 logs
drwxr-xr-x 5 django webapps 4096 Nov 30 13:36 narcisse
-rw-r--r-- 1 django webapps 59 Nov 30 16:11 pip-selfcheck.json
-rw-r--r-- 1 django webapps 75 Nov 30 16:10 pyvenv.cfg
-rw-r--r-- 1 django webapps 85 Nov 30 15:50 README.md
drwxrwxrwx 2 django webapps 4096 Nov 30 17:51 run
我有一个/etc/supervisor/conf.d/filename,看起来像这样:
[program:site]
command = /var/www/site/bin/gunicorn_start -user=django
user = django
stdout_logfile = /var/www/site/logs/gunicorn_supervisor.log
redirect_stderr = true
我的 gunicorn_start 位于/ var / www / site / bin()内,如下所示:
NAME="api"
DJANGODIR=/var/www/site/site
SOCKFILE=/var/www/site/run/gunicorn.sock
USER=django
GROUP=webapps
NUM_WORKERS=3
DJANGO_SETTINGS_MODULE=api.settings
DJANGO_WSGI_MODULE=api.wsgi
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
exec ../bin/gunicorn ${DJANGO_WSGI_MODULE}:application \
--name $NAME \
--workers $NUM_WORKERS \
--user=$USER --group=$GROUP \
--bind=unix:$SOCKFILE \
--log-level=debug \
--log-file=-
最后是nginx conf文件:
upstream your-gunicorn {
server unix:/var/www/site/run/gunicorn.sock fail_timeout=0;
}
server {
listen 80 default;
client_max_body_size 4G;
server_name <ip_address>;
keepalive_timeout 70;
access_log /var/log/nginx/site.access_log;
error_log /var/log/nginx/site.error_log;
root /var/www/site/;
location /static/ {
autoindex on;
alias /var/www/site/site/static/;
expires 1M;
access_log off;
add_header Cache-Control "public";
proxy_ignore_headers "Set-Cookie";
}
location @proxy_to_app {
proxy_set_header X-Forwarded-For $proxy_add_x_forwarded_for;
proxy_set_header Host $http_host;
proxy_redirect off;
proxy_pass http://127.0.0.1;
}
location / {
try_files $uri @proxy_to_app;
}
}
我有尝试过每种键盘组合的感觉。找不到问题所在。
启动后,我会不断在gunicorn日志中收到此“不允许操作”错误。
这是完整的输出:
[2018-11-30 17:49:28 +0000] [13849] [INFO] Starting gunicorn 19.9.0
[2018-11-30 17:49:28 +0000] [13849] [DEBUG] Arbiter booted
[2018-11-30 17:49:28 +0000] [13849] [INFO] Listening at: unix:/var/www/site/run/gunicorn.sock (13849)
[2018-11-30 17:49:28 +0000] [13849] [INFO] Using worker: sync
[2018-11-30 17:49:28 +0000] [13923] [INFO] Booting worker with pid: 13923
[2018-11-30 17:49:28 +0000] [13923] [ERROR] Exception in worker process
Traceback (most recent call last):
File "/var/www/site/lib/python3.6/site-packages/gunicorn/arbiter.py", line 583, in spawn_worker
worker.init_process()
File "/var/www/site/lib/python3.6/site-packages/gunicorn/workers/base.py", line 93, in init_process
initgroups=self.cfg.initgroups)
File "/var/www/site/lib/python3.6/site-packages/gunicorn/util.py", line 165, in set_owner_process
os.setgid(gid)
PermissionError: [Errno 1] Operation not permitted
谢谢您的帮助。
朱利安
答案 0 :(得分:1)
因此,在 Haken Lid 的帮助下,我设法修复了我的体系结构。
这是我所做的:
修复的nginx配置文件
upstream your-gunicorn {
server unix:/var/www/site/run/gunicorn.sock fail_timeout=0;
}
更改为:
upstream gunicorn_upstream {
server unix:/var/www/site/run/gunicorn.sock fail_timeout=0;
}
并且:
proxy_pass http://127.0.0.1;
更改为:
proxy_pass http://gunicorn_upstream;
修复了gunistart_start文件
最后一行从:
exec ../bin/gunicorn ${DJANGO_WSGI_MODULE}:application \
--name $NAME \
--workers $NUM_WORKERS \
--user=$USER --group=$GROUP \
--bind=unix:$SOCKFILE \
--log-level=debug \
--log-file=-
收件人:
exec ../bin/gunicorn ${DJANGO_WSGI_MODULE}:application \
--name $NAME \
--workers $NUM_WORKERS \
--bind=unix:$SOCKFILE \
--log-level=debug \
--log-file=-
我犯的一个错误实际上很愚蠢,因为我评论了:
--user=$USER --group=$GROUP
该行的,其行为就像也注释了该行的其余部分。因此,基本上,所有内容都在nginx配置文件中。
现在已修复。谢谢
朱利安