在生产中使用 Sanic 的内置网络服务器

Using Sanic's inbuilt webserver in Production

Django documentation 关于其开发服务器的声明:

Don’t use this server in anything resembling a production environment. It’s intended only for use while developing. (We’re in the business of making Web frameworks, not Web servers.)

Sanic's 部署文档没有说我们不能在生产中使用它内置的服务器。它指出:

Deploying Sanic is very simple using one of three options: the inbuilt webserver, an ASGI webserver, or gunicorn. It is also very common to place Sanic behind a reverse proxy, like nginx.

对我来说,这意味着从 Apache 中解放出来。这也意味着Nginx、Gunicorn、Daphne、Uvicorn、Hypercorn等是可选的。

但是,我在 Sanic: python web server that's written to die fast 中发现了一些关于其内置服务器的负面评论。另一方面,他们的 github 存储库似乎非常活跃。他们是否解决了 Reddit post 中提到的问题?

我是不是漏掉了什么?

问题 1 涉及请求大小和超时设置,这些设置允许通过向服务器发送过多数据来进行 DoS 攻击。这些设置可以由管理员根据服务器硬件和站点的要求进行调整 运行。话虽这么说,默认值可能应该低于它们,以使对未配置服务器的此类攻击更加困难。

问题 2 声称在流式响应中没有背压处理。当前版本确实有流量控制,因此得到适当的背压控制,避免了此类问题。由于在Python的asyncio协议设计中严重忽视了这一点,因此过去很多应用程序都存在此类问题,在撰写博客时想必也包括Sanic。

像现在一样,Sanic 服务器当然可以 运行 直接在 Internet 上,事实上,这比 运行在 nginx 或 Apache 后面使用 Django 更安全,其中任何 long-持久的 POST 请求会阻塞整个 Django worker。