简体   繁体   English

为什么我们在部署rails应用程序时需要一个apache服务器?

[英]why do we need an apache server when we deploy a rails app?

我虽然可以用webrick或mongrel部署它

Most Ruby application servers will only run a single Ruby process (and Ruby has a global interpreter lock that makes multithreading quite pointless), which means that it can only serve one request at a time. 大多数Ruby应用程序服务器只运行一个Ruby进程(并且Ruby有一个全局解释器锁,使多线程毫无意义),这意味着它一次只能处理一个请求。 To say the least, this will not give you very good performance. 至少可以说,这不会给你很好的表现。

There are two ways around this: either you run several Ruby application servers and put a load balancer or reverse proxy in front of them, eg Nginx or Apache in front of a pack of Mongrels or Thin servers (the number of processes you run reflects the number of requests you will be able to handle in parallel). 有两种方法可以解决这个问题:要么运行多个Ruby应用程序服务器,要么在它们前面放置负载均衡器或反向代理,例如在一堆Mongrels或Thin服务器前面的Nginx或Apache(运行的进程数反映了您将能够并行处理的请求数)。 Or you run Passenger, which is an Apache or Nginx module that manages a pool of applications that can dynamically grow and shrink as the load changes. 或者运行Passenger,它是一个Apache或Nginx模块,用于管理可随负载变化而动态增长和缩小的应用程序池。 The first option gives you more configuration options, but the second option is easier to manage. 第一个选项为您提供了更多配置选项,但第二个选项更易于管理。 Which one you want depends on your use case. 你想要哪一个取决于你的用例。

There are of course other solutions too, but they are for more specific use cases. 当然还有其他解决方案,但它们适用于更具体的用例。 You can, for example, write a very performant application and deploy it with Thin -- but it requires that you write an event driven application. 例如,您可以编写一个性能非常高的应用程序并使用Thin部署它 - 但它要求您编写一个事件驱动的应用程序。 You can't deploy a Rails app and expect the same performance. 您无法部署Rails应用程序并期望获得相同的性能。

Before Phusion Passenger allowed Rails hosting with Apache and nginx, deploying a rails app was scary and difficult. 在Phusion Passenger允许Rails托管Apache和nginx之前,部署rails应用程序是可怕和困难的。 Apache is a very mature web server which scales easily and is configurable to meet many needs. Apache是​​一个非常成熟的Web服务器,可以轻松扩展并可配置以满足许多需求。 (nginx is not as mature but is very efficient, also very configurable and a great alternative to Apache for rails hosting.) Webrick and Mongrel are great for development, but unless you are an expert, it is difficult to set them up for production use. (nginx不是那么成熟,但非常高效,也是非常可配置的,也是Apache托管主机的绝佳替代品。)Webrick和Mongrel非常适合开发,但除非你是专家,否则很难将它们设置为生产使用。

你可以在技术上,但通常不想这样做,因为在提供像CSS或图像这样的静态文件时会产生相当大的开销。

There are any number of ways you can deploy a Rails app without involving Apache, but Apache is the most popular server around, the most mature server around and among the most stable and scalable. 有许多方法可以在不涉及Apache的情况下部署Rails应用程序,但Apache是​​最受欢迎的服务器,最成熟的服务器和最稳定和可扩展的服务器。 WEBrick and Mongrel both have their own merits, but Apache is just the default assumption for Web servers and the path of least resistance in most cases. WEBrick和Mongrel都有自己的优点,但Apache只是Web服务器的默认假设,在大多数情况下是阻力最小的路径。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM