python - 在生产环境中运行 Python Pyramid 服务器,无需 Apache

标签 python apache pyramid wsgi amazon-ecs

因此,我们过去在生产环境中使用 Apache 来运行 Pyramid 服务器。但我们正在转向 Docker 容器化,以便更轻松地进行产品部署等,并且我们希望坚持“每个容器一个进程”的理念。因此,我们只需要 1 个 python 进程,而不是在容器 + 4 个 python 进程中运行 Apache。

所以我的问题是 - 有没有办法直接在生产环境中运行 Pyramid 服务器?不使用WSGI+Apache?

https://www.digitalocean.com/community/tutorials/how-to-use-the-pyramid-framework-to-build-your-python-web-app-on-ubuntu

我的理解是pserve只是为了开发?

创建一个application.py文件并填充以下内容:

from wsgiref.simple_server import make_server
from pyramid.config import Configurator
from pyramid.response import Response

def hello_world(request):
    return Response('<h1>Hello world!</h1>')

if __name__ == '__main__':
    config = Configurator()
    config.add_view(hello_world)
    app = config.make_wsgi_app()
    server = make_server('0.0.0.0', 8080, app)
    server.serve_forever()

以上可以作为生产级服务器使用吗?

最佳答案

最新的官方建议是每个容器一个问题。来自 Docker docs (强调我自己的):

Each container should have only one concern. Decoupling applications into multiple containers makes it easier to scale horizontally and reuse containers. For instance, a web application stack might consist of three separate containers, each with its own unique image, to manage the web application, database, and an in-memory cache in a decoupled manner.

Limiting each container to one process is a good rule of thumb, but it is not a hard and fast rule. For example, not only can containers be spawned with an init process, some programs might spawn additional processes of their own accord. For instance, Celery can spawn multiple worker processes, and Apache can create one process per request.

就您而言,您的 Web 应用程序服务器是一个单一的问题。运行 Apache+WSGI 完全没问题。不用担心进程——这是 Apache 的工作。

为了更好地理解“单一关注”规则,this post很好地概述了它试图解决的问题。

关于python - 在生产环境中运行 Python Pyramid 服务器,无需 Apache,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/57894461/

相关文章:

python - 如何运行当前行并在 VS Code 中前进? ( window )

java - Ant:NoClassDefFound 异常

python - Pyramid 中的 HTML 文件响应

python - 如何将 pystache 与 Pyramid 集成?

python - Apache 不提供 django 管理静态文件

Celery Beat - Pyramid 邮件

python - OpenCV DNN因keras DenseNet121而失败

python - 值错误 : unsupported format character in mysql scrapy pipline

python - a[ :] = b and a = b[:]? 之间的区别(Python)

regex - Apache mod_rewrite 将双斜杠转换为一个斜杠