Pyramid + Nginx + uWSGI Server 500错误

我有一个使用Pyramid框架以Python编写的uWSGI应用程序。

Nginxconfiguration如下(我遗漏了一些,但我不认为他们会很重要):

upstream uwsgicluster { server 127.0.0.1:8989; } # Proxying connections to application servers location / { include uwsgi_params; uwsgi_pass uwsgicluster; proxy_redirect off; proxy_set_header Host $host; proxy_set_header X-Real-IP $remote_addr; proxy_set_header X-Forwarded-For $proxy_add_x_forwarded_for; proxy_set_header X-Forwarded-Host $server_name; } 

uWSGIconfiguration如下(使用.ini文件):

 [uwsgi] socket = 127.0.0.1:8989 master = true home = /home/user/userenv paste = config:/home/user/userenv/app/production.ini harakiri = 30 logto = /home/user/userenv/log/app.log 

一切都很好。 uWSGI由Supervisorpipe理。

我想要做的是在Nginx上获得我的HTTP 500响应,并在某些情况下让浏览器响应。

目前,当存在HTTP 500时,堆栈跟踪将正确地转到日志文件,但零字节将返回给Nginx。

POST / jsonendpoint =>在2毫秒中产生0个字节(pid:19826 | app:0 | req:117/117] 192.168.10.54(){38 vars in 469 bytes} [Tue Nov 11 02:46:53 2014] HTTP / 1.1 500)0个字节中的0个标题(核心0上的0个开关)

在此之前是一个Python堆栈跟踪和一个典型的Pythonexception没有处理。 一切都按预期工作。

问题:我怎样才能让uWSGI将500响应的内容返回给Nginx(以及浏览器)。 现在它生成0个字节。 这是我需要在我的Python框架中进行更深层次的configuration吗?

作为参考,我正在使用一个完全标准的(数据库连接string以外的零更改)金字塔configuration: https : //github.com/Pylons/pyramid/blob/master/pyramid/scaffolds/alchemy/production.ini_tmpl

下面编辑

我想出了这一个。

答案是我的金字塔应用程序没有返回任何数据。

如果您定义了一个视图,如下所示,使用exception的上下文,此视图针对所有exception运行。 我仍然在研究如何获得整个堆栈跟踪(因为这不是在Pythonexception处理程序中,但是无论如何,主要问题已被回答)。

 @view_config(context=Exception) def failed_validation(exc, request): msg = exc.args[0] if exc.args else "" response = Response('Exception: %s' % msg) 

所以,一个子问题是:如何获取整个堆栈跟踪。 这可能是一个Pyramid / Python结合的答案。