带有 NGiNX 的 uWSGI 上的 Django 运行 - INI 方法不起作用
Django Running on uWSGI with NGiNX - INI Method Not Working
我正在从 apache
和 mod_wsgi
迁移到 nginx
和 uwsgi
。我是 运行 Python 3.3 和 Django 1.7。我在虚拟环境中通过 apt-get
安装了 nginx
,通过 pip
安装了 uwsgi
。
当我使用此命令时,我已经设置并运行了我的 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;
}
}
我从各种来源把它放在一起,它似乎有正确的成分,但经过多次试验和错误后它仍然不起作用。
我不确定我读到的是哪个文档导致我走上了这条错误的道路,但我只使用了 INI 套接字配置的编号:
# WRONG!!!
socket = 8001
应该是,就像手动命令行方法一样:
# CORRECT
socket = :8001
或者像大多数文档描述的那样:
# ALSO CORRECT, and probably better
socket = 127.0.0.1:8001
我认为这是我可能确实正确配置了这段配置的一次,但我匆忙中将它与其他变量一起更改(故障排除禁忌)并随身携带,错误.. .
感谢您的反馈和意见。希望这至少能帮助其他人 ;-)
我正在从 apache
和 mod_wsgi
迁移到 nginx
和 uwsgi
。我是 运行 Python 3.3 和 Django 1.7。我在虚拟环境中通过 apt-get
安装了 nginx
,通过 pip
安装了 uwsgi
。
当我使用此命令时,我已经设置并运行了我的 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;
}
}
我从各种来源把它放在一起,它似乎有正确的成分,但经过多次试验和错误后它仍然不起作用。
我不确定我读到的是哪个文档导致我走上了这条错误的道路,但我只使用了 INI 套接字配置的编号:
# WRONG!!!
socket = 8001
应该是,就像手动命令行方法一样:
# CORRECT
socket = :8001
或者像大多数文档描述的那样:
# ALSO CORRECT, and probably better
socket = 127.0.0.1:8001
我认为这是我可能确实正确配置了这段配置的一次,但我匆忙中将它与其他变量一起更改(故障排除禁忌)并随身携带,错误.. .
感谢您的反馈和意见。希望这至少能帮助其他人 ;-)