[error] [nginx+uwsgi] upstream prematurely closed connection while reading response header from ups
Posted 何处繁花笙歌落
tags:
篇首语:本文由小常识网(cha138.com)小编为大家整理,主要介绍了[error] [nginx+uwsgi] upstream prematurely closed connection while reading response header from ups相关的知识,希望对你有一定的参考价值。
upstream prematurely closed connection while reading response header from upstream, client: 10.16.151.131, server: localhost, request: "POST /hsvltnprjct/predict/ HTTP/1.1", upstream: "http://10.16.195.51:8080/hsvltnprjct/predict/", host: "api.web"
1.问题描述
通过postman调用django后端服务接口,返回如下页面,但是只是偶尔返回,有时正常响应
查看nginx报错日志,如下:
2.问题解决
通过网上百度各种方案,如下:
- 增加keepalive 30000; 无效
- 修改proxy_buffer_size参数,也无效
- 关闭proxi_buffering=off; 也无效
突然想到不一定是nginx的问题,是不是后端服务问题呢?
- 测试1:穿过nginx直接访问uwsgi启动的nginx服务,发现服务无响应的概率几乎60%。
- 测试2:直接通过python manage.py启动服务,访问服务发现一切正常
由上反映出问题不在nginx,在uwsgi,这样就好处理了
修改uwsgi配置文件,将buffer-size=32768改为3276800
buffer-size=3276800
重启服务,再次访问,服务回归正常。不容易,坑太多了
以上是关于[error] [nginx+uwsgi] upstream prematurely closed connection while reading response header from ups的主要内容,如果未能解决你的问题,请参考以下文章
从上游读取响应头时,Nginx uwsgi(104:由对等方重置连接)
DJANGO-天天生鲜项目从0到1-015-部署-uWSGI+Nginx