我正在從apache
和mod_wsgi
遷移到nginx
和uwsgi
。我正在運行Python 3.3和Django 1.7。我在虛擬環境中通過apt-get
和uwsgi
通過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;
}
}
我把這個來源放在一起,它似乎有正確的成分,但它仍然沒有工作後,有點反覆試驗。
看看這個:http://www.django-tips.com/tip/deploying-django-project-with-nginx-and-uwsgi/3/ – doniyor
'module = rebo.wsgi.local'應該是'module = rebo.wsgi:application'? – doniyor
該模塊實際上位於'rebo.wsgi.local',因此您認爲它應該是'rebo.wsgi.local:application'? – nicorellius