在 Heroku 上,运行 Gunicorn 在前面安全吗?

On Heroku, is it safe to run Gunicorn out in front?

我读到的几乎所有关于在 Heroku 上部署 Python 的描述基本上都是:

  1. gunicorn添加到`requirements.txt
  2. web: gunicorn wsgi:application添加到Procfile
  3. 利润

Heroku docs本质上也是一样的。

但是,Gunicorn docs make it pretty clear that it "is best to use Gunicorn behind HTTP proxy server", and it specifically recommends Nginx. Heroku doesn't mention this, and nobody else does. In fact, everybody I know that runs Gunicorn on Heroku runs it as a standalone server. With WhiteNoise 您甚至可以相当高效地提供静态文件,所以这不是一个大问题,直到流量和成本增长超出可接受范围。

是 Heroku 的 HTTP 路由处理了很多 Gunicorn 没有处理的情况(slowloris 攻击等),这使得它安全,还是所有这些人(包括 Heroku)只是简单地采取技术低路,因为它更容易?

Heroku is the proxy server 在这种情况下。

你是对的:推荐 gunicorn 的人走的是技术低级路线,因为它更容易。

Heroku 确实提供了 some buffering,但它不足以抵御 slowloris 类型的攻击。

这里有一篇不错的博客 post,其中更详细地解释了: http://blog.etianen.com/blog/2014/01/19/gunicorn-heroku-django/

推荐的解决方案是使用 Waitress,它是纯 Python 网络服务器,可以正确处理缓冲。