Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

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

i though we could just deploy it with webrick or mongrel

like image 322
fenec Avatar asked Dec 06 '10 20:12

fenec


People also ask

Why do we need an Apache server?

Apache HTTP web servers are used by over 67% of all web servers in the world. Apache web servers are easy to customize environments, they're fast, reliable, and highly secure. This makes Apache web servers a common choice by best-in-class companies.

Does Rails use Apache?

The most common way to deploy a Rails application is with Apache and Passenger. Follow the steps below: Create a new file at installdir/httpd-vhosts.

Which server is used by Rails?

The Ruby standard library comes with a default web server named WEBrick. As this library is installed on every machine that has Ruby, most frameworks such as Rails and Rack use WEBrick as a default development web server.

Does heroku use Apache?

By default, Heroku will launch an Apache web server together with PHP to serve applications. However, a special circumstance apply to Symfony applications: the document root is in the web/ directory and not in the root directory of the application.


2 Answers

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. 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, e.g. 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). 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. 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. You can't deploy a Rails app and expect the same performance.

like image 155
Theo Avatar answered Oct 03 '22 16:10

Theo


Before Phusion Passenger allowed Rails hosting with Apache and nginx, deploying a rails app was scary and difficult. Apache is a very mature web server which scales easily and is configurable to meet many needs. (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.

like image 28
bowsersenior Avatar answered Oct 03 '22 15:10

bowsersenior