NGINX+;对等方重置uWSGI连接

NGINX+;对等方重置uWSGI连接,nginx,uwsgi,bottle,Nginx,Uwsgi,Bottle,我正在尝试使用uWSGI在NGINX上托管瓶子应用程序 这是我的nginx.conf location /myapp/ { include uwsgi_params; uwsgi_param X-Real-IP $remote_addr; uwsgi_param Host $http_host; uwsgi_param UWSGI_SCRIPT myapp; uwsgi_pass 127.0.0.1:8080;

我正在尝试使用uWSGI在NGINX上托管瓶子应用程序

这是我的nginx.conf

location /myapp/ {
        include uwsgi_params;
        uwsgi_param X-Real-IP $remote_addr;
        uwsgi_param Host $http_host;
        uwsgi_param UWSGI_SCRIPT myapp;
        uwsgi_pass 127.0.0.1:8080;
    }
我是这样运行uwsgi的

uwsgi --enable-threads --socket :8080 --plugin python -- wsgi-file ./myApp/myapp.py
我正在使用POST请求。为此,请使用dev Http客户端。当我发送请求时,它将无限大

http://localhost/myapp
uWSGI服务器接收请求并打印

[pid: 4683|app: 0|req: 1/1] 127.0.0.1 () {50 vars in 806 bytes} [Thu Oct 25 12:29:36 2012] POST /myapp => generated 737 bytes in 11 msecs (HTTP/1.1 404) 2 headers in 87 bytes (1 switches on core 0)
但在nginx错误日志中

2012/10/25 12:20:16 [error] 4364#0: *11 readv() failed (104: Connection reset by peer) while reading upstream, client: 127.0.0.1, server: localhost, request: "POST /myApp/myapp/ HTTP/1.1", upstream: "uwsgi://127.0.0.1:8080", host: "localhost"

怎么办?

如果不在应用程序中读取数据,就无法从客户端发布数据。虽然这在uWSGI中不是问题,但nginx将失败。你可以用UWSGi的后缓冲选项来伪造这个东西,以自动从套接字读取数据(如果可用的话),但是你最好“修复”(即使我不认为是bug)你的应用程序

<强>不使用线程!<强>

我对uwsgi下Python中的全局解释器锁也有同样的问题。 当我不使用线程时-不重置连接

uwsgi配置示例(服务器上的1Gb Ram)


确保在应用程序中使用post数据

例如,如果您有一个Django/python应用程序

def my_视图(请求):
#确保读取post数据,即使您不需要它
#如果不这样做,您将得到一个:failed(104:由对等方重置连接)
data=request.data
返回HttpResponse(“Hello World”)

一些详细信息:

由于uwsgi无法知道在某个时刻是否仍然需要请求,因此当请求主体未被使用时,就会出现此问题。因此,uwsgi将继续保留数据,直到数据被消耗或直到nginx重置连接(因为上游超时)

uwsgi的作者解释道:

08:21plaes:您的删除请求(不是响应)是否有正文?
08:40你在你的应用程序中读到了这个主体吗?
08:41从nginx日志看,它似乎有一个主体,而你没有在应用程序中阅读它
08:43所以删除请求不应该有正文?
08:43不,我的意思是如果一个请求有一个主体,你必须阅读/消费它
08:44否则插座将被撞坏

因此,要解决此问题,您需要确保始终读取整个请求正文,或者在不需要时不发送正文(例如删除)。

您是否使用应用程序中的post数据?这最终解决了我在nginx uwsgi django实现中遇到的问题。我正在构建一个存根视图,最初并不关心入站xml。较小的入站xml可以工作,但较大的入站xml会被对等方重置。一旦我将
body=request.body
添加到视图中,任何大小的帖子都开始工作了。这也是我在Django/UWSGI/Nginx堆栈上遇到的问题。我不知道这是件事。这方面是否有任何文档/资源?为什么我必须使用POST数据?编辑:这里有一些细节(尽管非常模糊):这帮助很大!非常感谢。
[root@mail uwsgi]# cat myproj_config.yaml 
uwsgi:
    print: Myproject Configuration Started
    socket: /var/tmp/myproject_uwsgi.sock
    pythonpath: /sites/myproject/myproj
    env: DJANGO_SETTINGS_MODULE=settings
    module: wsgi
    chdir: /sites/myproject/myproj
    daemonize: /sites/myproject/log/uwsgi.log
    max-requests: 4000
    buffer-size: 32768
    harakiri: 30
    harakiri-verbose: true
    reload-mercy: 8
    vacuum: true
    master: 1
    post-buffering: 8192
    processes: 4
    no-orphans: 1
    touch-reload: /sites/myproject/log/uwsgi
    post-buffering: 8192
08:21 < unbit> plaes: does your DELETE request (not-response) have a body ?
08:40 < unbit> and do you read that body in your app ?
08:41 < unbit> from the nginx logs it looks like it has a body and you are not reading it in the app
08:43 < plaes> so DELETE request shouldn't have the body?
08:43 < unbit> no i mean if a request has a body you have to read/consume it
08:44 < unbit> otherwise the socket will be clobbered