为什么要在框架Web服务器前使用http服务器?

jua*_*ara 20 ruby scala lift sinatra playframework

Web应用程序框架(如sinatra(ruby),play(scala),lift(scala))生成一个侦听特定端口的Web服务器.

我知道有一些原因,如安全性,群集以及在某些情况下的性能,可能会导致我在我的Web应用程序前面使用Apache Web服务器.

根据您的经验,您有任何理由吗?

Pet*_*ons 43

  • 任何Web应用程序的一部分都是完全标准化和商品化的功能.像nginx或apache这样成熟的Web服务器可以执行以下操作.他们可以以一种非常可能更正确,更高效,更稳定,更安全,更熟悉系统管理员的方式执行以下操作,并且比您在应用程序服务器中重写的任何内容都更容易配置.
    • 提供静态文件,如HTML,图像,CSS,JavaScript,字体等
    • 处理虚拟主机(单个IP地址上的多个域)
    • URL重写
    • 主机名重写/重定向
    • TLS终止(感谢@ emt14)
    • 压缩(感谢@JacobusR)
  • 单独的Web服务器可以在应用程序服务器重新启动或崩溃时提供"向下维护"页面
  • 反向代理可以为您的应用程序框架提供负载平衡和容错
  • Web服务器具有内置和测试机制,用于以root身份绑定到特权端口(低于1024),然后作为非特权用户执行.大多数Web应用程序框架默认不执行此操作.
  • Mature web servers are battle hardened and stable. By stable, I mean that they quite literally almost never crash. Your web application is almost certainly far less stable. This gives you the ability to at least serve a pretty error page to the user saying your application is down instead of the web browser just displaying a generic "could not connect" error.

And just in case you want the semi-official answer from Isaac Schluetter at the Airbnb tech talk on January 30, 2013 around 40 minutes in he addresses the question of whether node is stable & secure enough to serve connections directly to the Internet. His answer is essentially "yes" it is fine. So you can do it and you will probably be fine from a stability and security standpoint (assuming you are using cluster to handle unexpected termination of an app server process), but as detailed above the reality of current operations is that still almost everybody runs node behind a separate web server or reverse proxy/cache.