我根据https://tghw.com/blog/multiple-django-and-flask-sites-with-nginx-and-uwsgi-emperor设置了django + uwsgi + nginx服务器
页面在快速返回时工作正常。但我有一个页面大约需要30秒才能返回,在该页面上,nginx日志显示连接超时错误,并在浏览器上显示空白页面(非错误页面)。
以下是我的配置文件:
server {
listen 8000;
server_name localhost;
root /var/www/consent_architecture;
location / {
include uwsgi_params;
uwsgi_pass unix:/var/www/run/crediwatch_consent.sock;
uwsgi_read_timeout 300;
}
}
[uwsgi]
# Variables
base = /var/www/consent_architecture
app = wsgi
# Generic Config
chdir = /var/www/consent_architecture
home = %(base)/venv
plugins = http, python
processes = 5
pythonpath = %(base)
socket = /var/www/run/%n.sock
module = %(app)
logto = /var/log/uwsgi/%n.log
uwsgi日志显示该调用在~25秒内返回:
[pid: 18713|app: 0|req: 14/25] 127.0.0.1 () {50 vars in 1412 bytes} [Fri Aug 12 18:52:30 2016] POST /consent_server/confirmation => generated 750 bytes in 23503 msecs (HTTP/1.1 200) 2 headers in 88 bytes (1 switches on core 0)
但是nginx日志显示以下错误:
2016/08/12 18:53:33 [error] 21203#0: *1 upstream timed out (110: Connection timed out) while reading upstream, client: 127.0.0.1, server: localhost, request: "POST /consent_server/confirmation HTTP/1.1", upstream: "uwsgi://unix:/var/www/run/crediwatch_consent.sock:", host: "localhost:8000", referrer: "http://localhost:8000/consent_server/get_details?phone_number=...."
nginx conf中的超时设置为5分钟,uwsgi在30秒内返回,但nginx似乎没有读取它。任何人都知道为什么会发生这种情况?
版本:
nginx = 1.4.6, uwsgi = 2.0.13.1
答案 0 :(得分:0)
Nginx告诉你上游(uWSGI)已超时,因此在Nginx的配置中调整超时将无济于事。
尝试调整内部套接字超时。在uswgi.ini
中,添加:
socket-timeout = 60
P.S我看到你已经查看了25中的第14个请求了。还有其他请求需要更长的时间而忘记包含在日志中吗?