2015-06-30 65 views
0

我正在從apachemod_wsgi遷移到nginxuwsgi。我正在運行Python 3.3和Django 1.7。我在虛擬環境中通過apt-getuwsgi通過pip安裝nginx使用NGiNX運行uWSGI的Django - INI方法不起作用

我有我的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; 
    } 
} 

我把這個來源放在一起,它似乎有正確的成分,但它仍然沒有工作後,有點反覆試驗。

+0

看看這個:http://www.django-tips.com/tip/deploying-django-project-with-nginx-and-uwsgi/3/ – doniyor

+0

'module = rebo.wsgi.local'應該是'module = rebo.wsgi:application'? – doniyor

+0

該模塊實際上位於'rebo.wsgi.local',因此您認爲它應該是'rebo.wsgi.local:application'? – nicorellius

回答

0

我不知道該文件,我讀了帶領我沿着這條路徑出現故障,但我只用了INI配置socket數目:

# WRONG!!! 
socket = 8001 

應該是,只是llike手動命令行方法:

# CORRECT 
socket = :8001 

或者最喜歡的文檔描述:

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

我就覺得這e那些時候我可能確實有這樣的配置是正確的,但是急於將其與其他變量(故障排除禁止)一起更改並隨身攜帶,錯誤...

感謝反饋和評論。希望這會幫助至少一個其他人;-)