docker - 在 Nginx 中向 uWSGI 公开 Flask (connexion) 实例
问题描述
在运行我的 Docker 映像并请求 Swagger UI 时,我收到:502 Bad Gateway
.
我正在尝试在 nginx 上使用 uWSGI 运行 Connexion(基于 Flask 的 Swagger UI 生成器)。我认为这是因为 uWSGI 没有正确获取我的 Flask 实例。但是,在我看来,我的容器实例配置正确。
如果你看这里https://github.com/Microsoft/python-sample-vscode-flask-tutorial,我的应用程序的设置和配置是相似的,它可以正常工作。
根据 Connexion 文档,我应该能够使用
app = connexion.App(__name__, specification_dir='swagger/')
application = app.app # expose global WSGI application object
你可以在这里找到我完整的应用程序代码:
https://bitbucket.org/lammy123/flask_nginx_docker_connexion/src/master/
Flask/Connexion 对象在 application/__init__.py
uwsgi.ini:
[uwsgi]
module = application.webapp
callable = app
uid = 1000
master = true
threads = 2
processes = 4
__init__.py:
import connexion
app = connexion.App(__name__, specification_dir='openapi/')
app.add_api('helloworld-api.yaml', arguments={'title': 'Hello World Example'})
webapp.py:
from . import app # For application discovery by the 'flask' command.
from . import views # For import side-effects of setting up routes.
from . import app
import connexion
application = app.app
使用内置开发服务器运行代码可以工作。
预期行为是 Swagger UI 在以下位置可用:
http://localhost:5000/v1.0/ui/#/
从 Docker 容器运行时。
解决方案
推荐阅读
- python - 使用正则表达式的 Python 中的空格后跟括号(非惰性)
- ios - SwiftUI:ViewModifier 不监听 onReceive 事件
- java - 当前有哪些 Java 代码覆盖率工具可以从测试的角度显示覆盖率?
- php - getimagesize / fopen 连接被拒绝
- android - 从应用打开深层链接时应用崩溃
- angular - Angular 8从另一个组件读取布尔值到根组件
- vhdl - 我无法在 VHDL 中为我的输出赋值
- html - 让项目在导航栏折叠时向左对齐(引导程序)
- sparql - 验证每个主题都有一个类型的类
- javascript - src iframe 中的随机数