我的 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 连接。还有一个关于这个问题的 SO questin: ( Propagate http abort/close from nginx to uwsgi / Django )
关于nginx - uwsgi IOError : write error,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/34768527/