关于nginx:uwsgi IOError:写入错误
uwsgi IOError: write error
我的Django应用程序的nginx + uwsgi配置出现问题,我在uwsgi错误日志中不断收到此错误:
Wed Jan 13 15:26:04 2016 - uwsgi_response_writev_headers_and_body_do(): Broken pipe [core/writer.c line 296] during POST /company/get_unpaid_invoices_chart/ (86.34.48.7)
IOError: write error
Wed Jan 13 15:26:20 2016 - uwsgi_response_write_headers_do(): Broken
pipe [core/writer.c line 238] during GET
/gestiune/print_pdf/nir/136194/ (89.122.255.186) IOError: write error
我没有收到所有请求的消息,但每分钟确实收到了几个消息。
我进行了搜索,并且了解到发生这种情况是因为nginx在uwsgi要写入响应时已关闭与uwsgi的连接。
这看起来很奇怪,因为在我的Nginx配置中,我有以下内容:
include uwsgi_params;
uwsgi_pass unix:/home/project/django/sbo_cloud/site.sock;
uwsgi_read_timeout 600;
uwsgi_send_timeout 600;
uwsgi_connect_timeout 60;
我确定出现错误的请求都没有超过600秒超时。
知道为什么会这样吗?
谢谢
问题是客户端中止连接,然后Nginx关闭连接而不告诉uwsgi中止。 然后,当uwsgi返回结果时,套接字已经关闭。 Nginx在日志中写入499错误,而uwsgi则抛出IOError。
非最佳解决方案是告诉Nginx不要关闭套接字,并等待uwsgi返回响应。
将uwsgi_ignore_client_abort放在您的nginx.config中。
location @app {
include uwsgi_params;
uwsgi_pass unix:///tmp/uwsgi.sock;
# when a client closes the connection then keep the channel to uwsgi open. Otherwise uwsgi throws an IOError
uwsgi_ignore_client_abort on;
}
目前尚不清楚是否可以告诉Nginx关闭uwsgi连接。 关于此问题还有另一个问题:(Propagate http abort/close from nginx to uwsgi / Django)
另一种解决方案是将以下设置放入uWSGI配置中:
ignore-sigpipe = true
ignore-write-errors = true
disable-write-exception = true
博主遇到了在Django应用中使用Nginx和uWSGI时遇到的uwsgi.IOError: write error问题。错误日志显示在处理POST和GET请求时出现 Broken pipe。问题可能是由于客户端提前关闭连接,而Nginx没有通知uWSGI。解决方案包括在Nginx配置中添加uwsgi_ignore_client_abort选项,或者在uWSGI配置中启用ignore-sigpipe、ignore-write-errors和disable-write-exception选项。这有助于处理客户端异常断开连接的情况。
2万+

被折叠的 条评论
为什么被折叠?



