Rails server vs front end web server

258 views Asked by At

I was watching the RailsCast on PageCaching: http://railscasts.com/episodes/89-page-caching-revised and at one point in it Ryan Bates says something along the lines of, "the public directory is set up to serve static files by the front end web server".

This made me realize I don't really understand the difference of the Rails server and the 'front end' web server.

I was hoping someone could explain this to me, maybe an explanation for both my local environment, as well as in production on Heroku, since I recently upgraded to Cedar and am having to now manually deal with gzip compression, which according to a blog I read is because "in Cedar, requests no longer go through a proxy server (nginx)".

1

There are 1 answers

0
kik On

On heroku, you don't have such thing as "frontend webserver" anymore since cedar.

Before cedar, request from outside where handled by nginx (thus being a front server), which in turn asked local rails server (thin, unicorn, webrick, whatever) to produce the page.

If front server detected that the requested url was in fact corresponding to an existing file, it was serving it directly, without asking anything to rails server process. That's still how you manage, most of the time, requests on a dedicated server.

What heroku does now is to directly expose rails server to outside world, with no classic webserver like apache or nginx in the middle.

What it means for you using heroku is that you should upload your assets and cache files to a third party cdn server, to avoid having your precious rails process time used to serve those.

Or you can use action caching rather so that you write html in memcache rather than in public/. That's actually heroku's recommandation.

A note about your local environment : you probably use a rails server process directly too. That's what happen when you run rails server : it starts a webrick or thin server directly bound on port 3000. So, there's no "front server" there too.

Please also note that action and page caching are not standard anymore in rails-4 but provided by gem. The standard new mean for caching, russian doll caching, use memcache, so no problem for heroku here.