我在 Nginx 后面的远程服务器上有 django 1.3。
如果我使用 apache + mod_wsgi 运行 django,我可以查看 apache 日志文件中的错误。没关系,但我想在控制台中。
如果我运行 django 自己的开发服务器,只有当 DEBUG = False 时,我才会在控制台中收到堆栈跟踪错误。在 DEBUG 模式下控制台输出
Exception happened during processing of request from (..., ...)
Traceback (most recent call last):
File "/usr/local/python/lib/python2.7/SocketServer.py", line 284, in _handle_request_noblock
self.process_request(request, client_address)
File "/usr/local/python/lib/python2.7/SocketServer.py", line 310, in process_request
self.finish_request(request, client_address)
File "/usr/local/python/lib/python2.7/SocketServer.py", line 323, in finish_request
self.RequestHandlerClass(request, client_address, self)
File "/usr/local/python/lib/python2.7/site-packages/django/core/servers/basehttp.py", line 570, in __init__
BaseHTTPRequestHandler.__init__(self, *args, **kwargs)
File "/usr/local/python/lib/python2.7/SocketServer.py", line 641, in __init__
self.finish()
File "/usr/local/python/lib/python2.7/SocketServer.py", line 694, in finish
self.wfile.flush()
File "/usr/local/python/lib/python2.7/socket.py", line 301, in flush
self._sock.sendall(view[write_offset:write_offset+buffer_size])
error: [Errno 32] Broken pipe
我想弄清楚为什么?为什么 django 只输出未命名的异常?为什么它取决于 DEBUG 变量。
当我无权访问请求对象时,此错误主要发生在视图之外。所以我无法在中间件或使用日志处理程序中捕获它。
更新。我注意到如果我直接向 django 服务器请求,我永远不会得到 Broken pipe。那么Nginx代理django时可能会出现问题吗?