我在让 Django 和 uWSGI 在 Ubuntu (12) 上顺利运行方面遇到了麻烦。似乎 wsgi 正在加载,然后应用程序立即崩溃。uwsgi 日志都没有给我任何参考信息。我使用的是标准 Django 1.4 wsgi,uwsgi 配置如下:
[uwsgi]
project = djangoproject
base_dir = /home/www/mywebsite.com
uid = www-data
gid = www-data
plugins = http,python
processes = 4
harakiri = 60
reload-mercy = 8
cpu-affinity = 1
max-requests = 2000
limit-as = 512
reload-on-as = 256
reload-on-rss = 192
no-orphans = True
vacuum = True
master = True
logto = /var/log/uwsgi/%n.log
catch-exceptions
virtualenv = %(base_dir)/venv
chdir = %(base_dir)
module = %(project).wsgi
socket = /run/uwsgi/%n.sock
chmod-socket = 666
这是我的日志文件的内容:
[uWSGI] getting INI configuration from mywebsite.ini
*** Starting uWSGI 1.0.3-debian (32bit) on [Sun Oct 7 23:52:26 2012] ***
compiled with version: 4.6.2 on 20 February 2012 10:06:16
current working directory: /etc/uwsgi/apps-enabled
detected binary path: /usr/bin/uwsgi-core
limiting address space of processes...
your process address space limit is 536870912 bytes (512 MB)
your memory page size is 4096 bytes
*** WARNING: you have enabled harakiri without post buffering. Slow upload could be rejected on post-unbuffered webservers ***
uwsgi socket 0 inherited UNIX address /run/uwsgi/mywebsite.sock fd 3
Python version: 2.7.3 (default, Aug 1 2012, 05:27:35) [GCC 4.6.3]
Set PythonHome to /home/www/mywebsite.com/venv
Python main interpreter initialized at 0x9944570
your server socket listen backlog is limited to 100 connections
*** Operational MODE: preforking ***
PRINT STATEMENT FROM WSGI.PY
WSGI application 0 (mountpoint='') ready on interpreter 0x9944570 pid: 6130 (default app)
*** uWSGI is running in multiple interpreter mode ***
gracefully (RE)spawned uWSGI master process (pid: 6130)
spawned uWSGI worker 1 (pid: 6146, cores: 1)
set cpu affinity for worker 1 to 0
spawned uWSGI worker 2 (pid: 6147, cores: 1)
set cpu affinity for worker 2 to 1
spawned uWSGI worker 3 (pid: 6148, cores: 1)
set cpu affinity for worker 3 to 2
spawned uWSGI worker 4 (pid: 6149, cores: 1)
set cpu affinity for worker 4 to 3
我看不到任何可以解释应用程序崩溃原因的内容。我还向 wsgi.py 添加了打印语句,以确保它正确加载。
作为参考,这是我的 wsgi:
import os
os.environ.setdefault("DJANGO_SETTINGS_MODULE", "djangoproject.settings")
# This application object is used by any WSGI server configured to use this
# file. This includes Django's development server, if the WSGI_APPLICATION
# setting points here.
from django.core.wsgi import get_wsgi_application
application = get_wsgi_application()
答案1
我不认为 uWSGI(或 Django)崩溃了。uWSGI 在死亡/重新加载时非常冗长,而你的标题报告了“坏网关”错误,这是另一回事。检查你的网络服务器日志,也许是一些配置错误