Both are indeed HTTP server, but their focus is different. Mongrel is a fast HTTP server aimed mostly at Ruby-based applications. On top of that, it’s easily extensible with Ruby code. However, it’s not very good at serving static files, i.e. it’s slower than Apache and nginx. Also, Rails is single threaded, meaning that during the course of a request (calling a controller method until the actual rendering) the mongrel is locked.
To work around the above mentioned disadvantages of Mongrel and Rails, the preferred setup in a production app is to put either Apache or nginx as the main webserver and if a request for a non-static Rails page is received, to pass this to a number of underlying mongrels, let the mongrel hand back the rendered page to Apache/nginx and serve that page, together with static files such as images/stylesheets/… It might seem a bit daunting and complex at first, but once you actually implement it, it’s extremely powerful and stable (I have several apps that have been running for months to years on a server without a single restart).
It boils down to this, let Apache/nginx do what it’s best at, let the mongrel cluster do what it’s best at, everybody is happy.
Choosing nginx over Apache is mostly based on memory considerations. Apache is quite a hefty webserver, especially if all you actually do is serve some static files with it and balance the rest over a bunch of mongrels. Nginx is very lightweight and performant and can do the same job just as good as Apache. But if you’re familiar with Apache, don’t want to get the grips with nginx configuration and have lots of memory on your server, you can still go for Apache. On a basic VPS, nginx is a more suitable approach.
Peter De Berdt