我试图使用主机上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请求。 对于使用开发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的--post缓冲选项,从插座(如果可用)自动读取DATAS,但你最好要“修理”(即使我不认为这是一个错误)的东西你应用
确保消费应用程序中的您的文章数据
例如,如果你有一个Django / Python应用程序
def my_view(request):
# ensure to read the post data, even if you don't need it
# without this you get a: failed (104: Connection reset by peer)
data = request.DATA
return HttpResponse("Hello World")
一些细节: https://uwsgi-docs.readthedocs.io/en/latest/ThingsToKnow.html
当一个请求的主体没有被消耗,就会出现此问题,因为uwsgi无法知道它是否仍然会在某些时候是必要的。 所以uwsgi将继续保持到数据,直至其被消耗或直到nginx的重置连接(因为上游超时)。
uwsgi的作者解释它在这里 :
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
因此,要解决这个问题,你需要确保始终无论是读取整个请求体或不发送体,如果它是没有必要的(对于DELETE EG)。
不使用线程!
我有同样的问题与全球解释器锁在Python下uwsgi。 当我不使用threads-不连接复位。
uwsgi配置的实施例(1GB内存在服务器上)
[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