Rails and Nginx: caching

Rails using Phusion Passenger is actually pretty quick after Passenger has first loaded.

And adding caching makes it pretty zippy.

Adding caching via Nginx makes it super fast. Cached pages bypass Rails and are served directly by Nginx which is incredibly fast.

Here’s a guide to using Rails with Nginx. Assuming you’ve got both installed, you need to:

1. add a flag to enable, e.g.:

config.action_controller.perform_caching = true

2. add caches_page


class ProductsController < ActionController


  caches_page :index


  def index

    @products = Products.all



Rails guide on page caching:


Nginx page caching:


Note that this assumes your cache will be in the public/ folder. For a non-standard page cache directory you’ll need to use mod_rewrite.

Leave a Reply

Your email address will not be published. Required fields are marked *