Django使用NGiNX在uWSGI上运行 - INI方法不起作用

时间:2015-06-30 20:12:37

标签: django nginx uwsgi

我从apachemod_wsgi迁移到nginxuwsgi。我正在运行Python 3.3和Django 1.7。我通过nginxapt-get通过uwsgi在虚拟环境中安装了pip

我使用此命令设置并运行我的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;
    }
}

我已经从各种来源把它放在一起,它似乎有正确的成分,但它经过相当多的试验和错误后仍然无法正常工作。

1 个答案:

答案 0 :(得分:0)

我不确定我读过哪个文件引导我走这条错误的路径,但我只使用了INI套接字配置的编号:

# WRONG!!!
socket = 8001 

应该是,只是喜欢手动命令行方法:

# CORRECT
socket = :8001

或者像大多数文档描述的那样:

# ALSO CORRECT, and probably better
socket = 127.0.0.1:8001

我认为这一次我可能确实有这样的配置正确,但是在急速中,我将其与其他变量(故障排除禁止)一起更改并随身携带,错误...... < / p>

感谢您的反馈和意见。希望这将有助于至少一个其他人; - )