django upstream prematurely closed connection while reading response header from up

1. 环境

django + uwsgi + Nginx

2. 解决方式

1.必须要在uwsgi.ini中设置“limit-as”,该值是每个uwsgi进程占用的虚拟内存的最大限制。
2.检查是否设置了

proxy_http_version 1.1;
proxy_set_header Connection "";

Nginx默认使用HTTP1.0从后端获取响应返还给客户端,但是HTTP1.0不支持keepalive,因此需要配置proxy_http_version 1.1,proxy_set_header Connection默认close:通知后端服务器主动关闭连接,这样会导致任何一个客户端的请求都在后端服务器上产生了一个TIME-WAIT状态的连接。
3.检查uwsgi和Nginx中设置的各种timeout是否过短。

3. 参考资料

  1. https://www.cnblogs.com/succour/p/6305574.html
  2. https://www.cnblogs.com/jackluo/p/3410739.html
  3. https://monicalent.com/blog/2013/12/06/set-up-nginx-and-uwsgi/

猜你喜欢

转载自blog.csdn.net/lj1404536198/article/details/79138379