【发布时间】:2015-06-30 20:12:36
【问题描述】:
我正在从 apache 和 mod_wsgi 迁移到 nginx 和 uwsgi。我正在运行 Python 3.3 和 Django 1.7。我在虚拟环境中通过apt-get 和uwsgi 通过pip 安装了nginx。
当我使用此命令时,我的 Django 项目已设置并开始工作(localhost:8000 - 请参阅下面的 nginx 配置):
uwsgi --master --processes 4 --socket :8001 --wsgi-file wsgi.py
但是,当我将相同的配置放入 INI 文件时,它无法正常工作,并且出现错误的网关 502 错误:
502 Bad Gateway
nginx/1.1.19
这是uwsgi的配置:
[uwsgi]
base = /path/to/project
wsgi-file = %(base)/proj/wsgi.py
logto = %(base)/proj/logs/uwsgi.log
chdir = %(base)
module = rebo.wsgi.local:application
home = /path/to/virtenvs/proj
master = true
processes = 4
socket = %(base)/proj/proj.sock
# I have tried ``socket = 8001`` as well
chmod-socket = 664
vacuum = true
以及启动命令:
uwsgi --ini /path/to/uwsgi.ini
当我检查日志时,一切似乎都正常(注意 <obfuscated> - 这些是路径,输出显示没有错误):
*** Starting uWSGI 2.0.10 (64bit) on [Tue Jun 30 12:45:34 2015] ***
compiled with version: 4.6.3 on 23 June 2015 22:56:27
os: Linux-3.2.0-86-generic #124-Ubuntu SMP Wed Jun 17 21:40:14 UTC 2015
nodename: <obfuscated>
machine: x86_64
clock source: unix
detected number of CPU cores: 4
current working directory: <obfuscated>
detected binary path: <obfuscated>
!!! no internal routing support, rebuild with pcre support !!!
chdir() to <obfuscated>
your processes number limit is 59540
your memory page size is 4096 bytes
detected max file descriptor number: 1024
lock engine: pthread robust mutexes
thunder lock: disabled (you can enable it with --thunder-lock)
uwsgi socket 0 bound to UNIX address <obfuscated> fd 3
Python version: 3.3.6 (default, Jan 28 2015, 16:31:42) [GCC 4.6.3]
Set PythonHome to <obfuscated>
*** Python threads support is disabled. You can enable it with --enable-threads ***
Python main interpreter initialized at 0x24dc440
your server socket listen backlog is limited to 100 connections
your mercy for graceful operations on workers is 60 seconds
mapped 363800 bytes (355 KB) for 4 cores
*** Operational MODE: preforking ***
WSGI app 0 (mountpoint='') ready in 1 seconds on interpreter 0x24dc440 pid: 12091 (default app)
mountpoint already configured. skip.
*** uWSGI is running in multiple interpreter mode ***
spawned uWSGI master process (pid: 12091)
spawned uWSGI worker 1 (pid: 12095, cores: 1)
spawned uWSGI worker 2 (pid: 12096, cores: 1)
spawned uWSGI worker 3 (pid: 12097, cores: 1)
spawned uWSGI worker 4 (pid: 12098, cores: 1)
最后,这是我的nginx 配置:
upstream proj {
server unix:///path/to/project/proj/proj.sock;
# I have tried ``server 127.0.0.1:8001;`` as well
}
server {
listen 8000;
server_name 127.0.0.1;
root /path/to/project;
access_log /var/www/proj/access.log;
error_log /var/www/proj/error.log;
location /static/ {
alias /path/to/project/proj/static/;
expires 30d;
}
location /media/ {
alias /path/to/project/proj/media/;
expires 30d;
}
location / {
include uwsgi_params;
uwsgi_pass proj;
}
}
我从各种来源将它放在一起,它似乎有正确的成分,但经过相当多的试验和错误后仍然无法正常工作。
【问题讨论】:
-
module = rebo.wsgi.local应该是module = rebo.wsgi:application? -
模块实际上位于
rebo.wsgi.local,所以你说它应该是rebo.wsgi.local:application? -
哪个模块?是的,
:application必须在那里 -
我很抱歉...我应该提到的,但我很早就尝试过。我已经尝试了几件事,但我没有一一列举。它没有帮助。