Nginx和mysql上行超时超时(110:连接超时)

2024-06-10 13:42:36 发布

您现在位置:Python中文网/ 问答频道 /正文

我的堆栈是带gevent循环、flask、mysql和python mysql.connector的uWSGI,我可以进行异步mysql查询。Lateley我在运行查询时在nginx日志中发现了以下错误。查询完成可能需要60秒。在堆栈的外部,查询可以工作。当我在笔记本电脑上本地运行内置flask dev服务器,并在半个世界范围内运行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;
             }

Tags: fromclientflaskserver堆栈onmysqltimeout