为什么uWSGI会抑制Django调试错误?

时间:2014-10-12 15:46:45

标签: python django nginx uwsgi

我正在使用Django运行nginx和uWSGI设置,但是即使启用了调试,Django中也不再显示错误:DEBUG = True。发生的所有错误都保存在uWSGI日志文件中。如何让Django再次显示它们?

nginx.conf:

server {
        access_log              /var/www/servers/myserver/development/logs/nginx_access.log;
        error_log               /var/www/servers/myserver/development/logs/nginx_error.log warn;
        server_name             localhost
        listen                  [::]:80;
        charset                 utf-8;

        client_max_body_size    75M;

        location / {
                uwsgi_pass      unix:/var/www/servers/myserver/development/sockets/myserver-dev.sock;
                include         /var/www/servers/myserver/development/configs/uwsgi_params;
                deny            all;
        }

        location /static {
                autoindex       on;
                alias           /var/www/servers/myserver/development/static;
        }

        location /media {
                autoindex       on;
                alias           /var/www/servers/myserver/development/media;
        }
}

uwsgi.conf:

[uwsgi]
;enable master process manager
master = true

;spawn 2 uWSGI worker processes
workers = 2

;unix socket (referenced in nginx configuration)
socket = /var/www/servers/myserver/development/sockets/myserver-dev.sock

# set mode of created UNIX socket
chmod-socket = 666

# place timestamps into log
log-date = true

# user identifier of uWSGI processes
uid = www-data
# group identifier of uWSGI processes
gid = www-data

; number of worker processes
;processes = 2
;vacuum = true

; project-level logging to the logs/ folder
;logto = /var/www/servers/myserver/development/logs/uwsgi.log


; django >= 1.4 project
chdir = /var/www/servers/myserver/development/webapp
wsgi-file = /var/www/servers/myserver/development/webapp/webapp/wsgi.py

;enable-threads = true

virtualenv = /var/www/servers/myserver/development/env
vacuum = true
env = DJANGO_SETTINGS_MODULE=webapp.settings
pidfile = /var/www/servers/myserver/development/logs/myserver-dev.pid
;harakiri = 20 # respawn processes taking more than 20 seconds
;max-requests = 5000 # respawn processes after serving 5000 requests

2 个答案:

答案 0 :(得分:0)

尝试仔细检查DEBUG == True实际上是否正确。我怀疑它不是。您可以使用以下代码在您的一个视图中执行此操作。

## inside a view function
from django.conf import settings
raise Exception('Value of DEBUG is %s' % (settings.DEBUG,))

重新启动uWSGI并尝试访问该视图。您应该立即查看您的假设是否正确。

答案 1 :(得分:0)

您是否在应用程序中配置了日志处理程序?我不再熟悉Django了,但是在使用uwsgi的debug = True的Flask中实际上会删除所有的日志处理程序。相反,您需要设置处理程序并使debug = False。

我怀疑一般错误处理在uwsgi中的运行方式与runserver相同 - http://librelist.com/browser/flask/2011/10/19/debug-when-deploy-in-uwsgi/#7be089baf631971dfb73a5a7b79e2248