gpt4 book ai didi

python - 上游超时(uWSGI + NGINX + Flask)

转载 作者:可可西里 更新时间:2023-11-01 10:53:43 32 4
gpt4 key购买 nike

我的应用程序有以下堆栈:

  1. NGINX (1.4.6)
  2. uWSGI(1.9.17.1-debian(64 位))
  3. flask
  4. python 3.4

问题NGINX 重启后一段时间(几分钟)一切正常。在那段时间之后,我收到“504 网关超时”错误。

NGINX 日志:

*13 upstream timed out (110: Connection timed out) while reading response header from upstream, client: 86.123.39.44, server: app.fc.com, request: "GET /dashboard/overview HTTP/1.1", upstream: "uwsgi://127.0.0.1:8001", host: "app.fc.com", referrer: "http://app.fc.com/dashboard/overview"

uWSGI 日志:

app.fc.com [pid: 100017|app: 0|req: 103/219] 86.123.39.44 () {44 vars in 859 bytes} [Fri Mar 9 06:24:22 2018] GET /login => generated 245 bytes in 1 msecs (HTTP/1.1 302) 3 headers in 131 bytes (1 switches on core 1)

我的 NGINX 配置是:

server {
listen 80;
listen [::]:80;

root /var/www/fc/website;
index index.html index.htm index.php;

# Make site accessible from http://localhost/
server_name app.fc.com;

location / {
sendfile on;
client_max_body_size 20M;
keepalive_timeout 0;

proxy_connect_timeout 10;
proxy_send_timeout 15;
proxy_read_timeout 20;

include uwsgi_params;
uwsgi_pass 127.0.0.1:8001;
#uwsgi_read_timeout 30;
#uwsgi_send_timeout 30;
uwsgi_connect_timeout 60;
uwsgi_ignore_client_abort on;
}
}

我的 uWSGI 配置是:

[uwsgi]
vhost = true
socket = :8001
#wsgi-file = /var/www/app.fc.com/reviewApp/wsgi.py
wsgi-file = /var/www/fc/app/wsgi.py
callable = app
processes = 2
threads = 4
chdir = /var/www/fc/app/

pythonpath = /var/www/fc/app/
pythonpath = /var/www/py3/lib/python3.4
virtualenv = /var/www/py3
plugins = python3

通常,对我的请求的响应持续不到 5 秒

最佳答案

解决方案

我只是在调用 Redis 的页面上发现了这种行为。我通过在 Redis 上为每个请求添加一个新连接并在 Redis 配置中设置一个连接空闲超时来解决(短期解决方案)这个问题。

其他发现

当连接在许多 uWSGI 线程之间共享时,似乎 Redis 在 300 秒不活动(这是出现此问题后的间隔)后挂起约 931 秒。

关于python - 上游超时(uWSGI + NGINX + Flask),我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/49191508/

32 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com