我的堆栈是带有gevent循环、flask、mysql和可以进行异步mysql查询的python mysql.connector的uWSGI。Lateley当我运行一个查询时,我在nginx日志中得到了下面的错误。查询可能最多需要60秒才能完成。在堆栈的外部,查询是有效的。当我在笔记本电脑上使用内置的flask dev服务器在本地运行,并在world..it运行到一半的时候访问mysql服务器。所以..我假设是nginx配置问题。
2013/01/05 01:49:48 [error] 7267#0: *2878 upstream timed out (110: Connection timed out) while reading response header from upstream, client: xxx.xxx.xxx.xxx, server: 127.0.0.1, request: "GET /ajax_grid?date_from=2013-01-02&date_to=2013-01-04&rt=crpr&a_dhx_rSeed=1357350534901 HTTP/1.1", upstream: "uwsgi://127.0.0.1:6000", host: "test.com", referrer: "http://test.com/"下面是我对nginx的相关选项。我应该调整什么才不会得到错误?
sendfile on;
tcp_nopush on;
tcp_nodelay on;
keepalive_timeout 65;
keepalive_requests 100000;
types_hash_max_size 2048;
proxy_read_timeout 200;
reset_timedout_connection on;
client_body_timeout 60;
send_timeout 2;
# server_tokens off;
# server_names_hash_bucket_size 64;
# server_name_in_redirect off;
server {
listen 80;
server_name 127.0.0.1;
location / {
include uwsgi_params;
uwsgi_buffering off;
#uwsgi_param X-Real-IP $remote_addr;
#uwsgi_param Host $http_host;
#uwsgi_pass uwsgi_dashboard;
uwsgi_pass 127.0.0.1:6000;
}发布于 2013-01-05 10:39:27
您可能需要设置uwsgi_read_timeout来延长nginx等待来自上游服务器的数据的时间。默认为60秒。
实际上,您真正需要做的是将长时间运行的作业转移到后台/异步任务中,因为大多数http客户端不愿意等待来自服务器的数据超过120秒;它们无论如何都会超时。使用像celery这样的异步处理框架,并允许客户端查询一个url来查找正在运行的作业的状态,可能会取消它,并在它完成后检索它。
如果您决定阻止您的wsgi容器,您可以在数据完成后使用重定向;并将某种类型的内容发送到客户端以保持连接。
https://stackoverflow.com/questions/14167910
复制相似问题