题
我有一个通过Nginx和UWSGI托管的Django应用程序。在某些非常简单的请求中,我会得到不同的行为和发布的行为,情况并非如此。
UWSGI守护程序日志:
[pid: 32454|app: 0|req: 5/17] 127.0.0.1 () {36 vars in 636 bytes} [Tue Oct 19 11:18:36 2010] POST /buy/76d4f520ae82e1dfd35564aed64a885b/a_2/10/ => generated 80 bytes in 3 msecs (HTTP/1.0 440) 1 headers in 76 bytes (0 async switches on async core 0)
[pid: 32455|app: 0|req: 5/18] 127.0.0.1 () {32 vars in 521 bytes} [Tue Oct 19 11:18:50 2010] GET /buy/76d4f520ae82e1dfd35564aed64a885b/a_2/10/ => generated 80 bytes in 3 msecs (HTTP/1.0 440) 1 headers in 76 bytes (0 async switches on async core 0)
Nginx AccessLog:
127.0.0.1 - - [19/Oct/2010:18:18:36 +0200] "POST /buy/76d4f520ae82e1dfd35564aed64a885b/a_2/10/ HTTP/1.0" 440 0 "-" "curl/7.19.5 (i486-pc-linux-gnu) libcurl/7.19.5 OpenSSL/0.9.8g zlib/1.2.3.3 libidn/1.15"
127.0.0.1 - - [19/Oct/2010:18:18:50 +0200] "GET /buy/76d4f520ae82e1dfd35564aed64a885b/a_2/10/ HTTP/1.0" 440 80 "-" "curl/7.19.5 (i486-pc-linux-gnu) libcurl/7.19.5 OpenSSL/0.9.8g zlib/1.2.3.3 libidn/1.15"
nginx errorlog:
2010/10/19 18:18:36 [error] 4615#0: *5 readv() failed (104: Connection reset by peer) while reading upstream, client: 127.0.0.1, server: localhost, request: "POST /buy/76d4f520ae82e1dfd35564aed64a885b/a_2/10/ HTTP/1.0", upstream: "uwsgi://unix:sock/uwsgi.sock:", host: "localhost:9201"
从本质上讲,如果我使用帖子,则nginx某个地方会失去响应,如果我使用get,则会失去响应。
有人知道这一点吗?
解决方案 4
经过进一步研究的幸运发现(http://answerpot.com/showthread.php?577619-Several%20bugs/page2)我发现了一些帮助...
提供 uwsgi_pass_request_body off;
nginx conf中的参数解决了此问题...
其他提示
经过 --post-buffering 1
到Uwsgi
这将自动缓冲所有HTTP主体> 1个字节
NGINX管理上游断开连接的方式提出了问题
我遇到了同一问题,但是在我的情况下,我无法禁用“ uwsgi_pass_request_body”,因为大多数时候(但并非总是如此)我的应用程序确实需要帖子数据。
这是我发现的解决方法,尽管UWSGI中没有解决此问题:http://permalink.gmane.org/gmane.comp.python.wsgi.uwsgi.general/813
import django.core.handlers.wsgi
class ForcePostHandler(django.core.handlers.wsgi.WSGIHandler):
"""Workaround for: http://lists.unbit.it/pipermail/uwsgi/2011-February/001395.html
"""
def get_response(self, request):
request.POST # force reading of POST data
return super(ForcePostHandler, self).get_response(request)
application = ForcePostHandler()
我面临着同样的问题。我尝试了上面的所有解决方案,但它们没有工作。在我的情况下忽略响应主体根本不是一个选择。
显然这是一个错误 nginx和uwsgi处理响应小于4052字节的邮政请求时
为我解决的问题是在UWSGI的参数列表中添加“ -PEP3333输入”。之后,所有帖子都正确返回。
我正在使用的nginx/uwsgi版本:
$ nginx -V
nginx: nginx version: nginx/0.9.6
$ uwsgi --version
uWSGI 0.9.7
不隶属于 StackOverflow