解决flask的502错误:upstream prematurely closed connection while reading response header from upstream
我在使用 tiangolo/uwsgi-nginx-flask 部署flask应用的时候,经常运行一会儿就出现502错误,重新启动容器后,就恢复。
且经常会出现数据更新后,刷新结果不一致。
docker作者的github中也有人遇到类似问题。https://github.com/tiangolo/uwsgi-nginx-flask-docker/issues/92
查询容器的日志可以看到upstream prematurely closed connection while reading response header from upstream
说是连接没有释放。现将解决方案记录一下:
http://flask.pocoo.org/docs/1.0/patterns/sqlalchemy/
在flask文档中有介绍使用一个装饰器来进行session释放。
from yourapplication.database import db_session @app.teardown_appcontext
def shutdown_session(exception=None):
db_session.remove()
具体适用方法如下:
一:
from flask import Flask
from yourapplication.database import db_session
app = Flask(name)
@app.teardown_appcontext
def shutdown_session(exception=None):
db_session.remove()
二:
from flask import Flask
from yourapplication.database import db_session
def create_app():
app = Flask(name)
return app
app = create_app() @app.teardown_appcontext
def shutdown_session(exception=None):
db_session.remove()
解决flask的502错误:upstream prematurely closed connection while reading response header from upstream的更多相关文章
- nginx error: upstream prematurely closed connection while reading response header from upstream
本篇文章由:http://xinpure.com/nginx-error-upstream-prematurely-closed-connection-while-reading-response-h ...
- Nginx" upstream prematurely closed connection while reading response header from upstream"问题排查
问题背景 我们这边是一个基于Nginx的API网关(以下标记为A),最近两天有调用方反馈,偶尔会出现502错误,我们从Nginx的error日志里看,就会发现有" upstream prem ...
- upstream prematurely closed connection while reading response header from upstream
upstream prematurely closed connection while reading response header from upstream nginx配置uwsgi的时候 ...
- 修复Nginx 502错误:upstream sent too big header while reading response header from upstream
原文出处:https://www.cnblogs.com/jpfss/p/10237463.html 便于以后参考我复制了过来! cookies的值超出了范围我是说 看看了一下日志 错误502 ups ...
- nginx log 错误502 upstream sent too big header while reading response header from upstream
cookies的值超出了范围我是说 看看了一下日志 错误502 upstream sent too big header while reading response header from upst ...
- nginx 错误502 upstream sent too big header while reading response header from upstream
查看nginx的错误日志,得到以下错误信息:upstream sent too big header while reading response header from upstream按字面意思理 ...
- 出现upstream sent too big header while reading response header from upstream错误
一个POS系统,出现upstream sent too big header while reading response header from upstream错误. 1.反向代理端,可以放到se ...
- nginx recv() failed (104: Connection reset by peer) while reading response header from upstream解决方法
首先说下 先看 按照ab 每秒请求的结果 看看 都有每秒能请求几个 如果并发量超出你请求的个数 会这样 所以一般图片和代码服务器最好分开 还有看看io瓶ding 和有没有延迟的PHP代码执行 0 先修 ...
- Nginx+PHP配置错误,日志:[error] 24324#0: *31 FastCGI sent in stderr: "Primary script unknown" while reading response header from upstream
一.问题现象 1.安装nginx.php.php-fpm后,浏览器访问php报错,“File not found”: 二.问题排查 1.检查nginx.php-fpm服务是否正常启动,均正常启动: 2 ...
随机推荐
- Java中BufferedReader、InputStreamReader、Scanner和System.in区别
Java中获取键盘输入值的方法以前写算法都是C/C++写的,现在用Java写,虽然算法是独立于语言的,但是Java从键盘获取输入确实有些不一样.在C/C++中我们可以用scanf和cin来获取用户从键 ...
- day13函数的嵌套定义,global、nonlocal关键字,闭包及闭包的运用场景,装饰器
复习 ''' 1.函数对象:函数名 => 存放的是函数的内存地址 1)函数名 - 找到的是函数的内存地址 2)函数名() - 调用函数 => 函数的返回值 eg:fn()() => ...
- pyhton抛出自定义的异常
用raise语句来引发一个异常.异常/错误对象必须有一个名字,且它们应是Error或Exception类的子类 下面是一个引发异常的例子: class ShortInputException(Exce ...
- Mysql 通用知识 2019-03-27
充电mysql 官网 https://www.mysql.com/ 以上是mysql的产品线,多数是收费的.只有社区版是免费的. 所以下面只说社区版community. MySQL Community ...
- 记一次IIS发布网站导致系统时常跳入登录页面的问题解决
服务器:winserver2012R2 iis 发布网站后,正常浏览网页,时常跳到登录页面,第一反应session过期,因为登录信息都存在session,但session 都是默认配置过期时间为20分 ...
- Linux之磁盘信息查看
一.磁盘情况查询 1.查看磁盘整体情况 命令:df 参数: -a:列出所有的文件系统,包括系统特有的/proc等文件系统 -k:以KB的容量显示各文件系统 -m:以MB的容量显示各文件系统 -h:以人 ...
- HBase详解
1. hbase简介 1.1. 什么是hbase HBASE是一个高可靠性.高性能.面向列.可伸缩的分布式存储系统,利用HBASE技术可在廉价PC Server上搭建起大规模结构化存储集群. H ...
- Click event doesn't work on dynamically generated elements
I couldn't get live or delegate to work on a div in a lightbox (tinybox). I used setTimeout successf ...
- sql group by聚合函数
如何让分组后count计算结果为0的记录也显示
- jmeter 上传附件 如图片
1.要勾选 Use multipart/form-data for POST,否则request中将不包含上传的文件 2.MIME类型为application/octet-stream 图如下:对应 ...