Nginx as Reverse Proxy and Cache for Thin/Sinatra

posted 2012-Jan-26
— updated 2012-Jan-27 runs a variety of different web applications, such as the page you’re reading now and ObjJob. Most of the web applications are written in Ruby, using the Sinatra as the web framework and Thin as the server. All of these apps, however, sit behind a single Nginx process that acts as the web server for all of

conceptual diagram showing the routing of web requests

As shown above, a single nginx.conf file controls multiple websites. You use a server{ … } block for each logical server, providing the host name used to match the rules therein.

Most of the magic takes place in the try_files command:

A future article will cover using sinatra/cache to automatically populate the cache directory based on controller requests. With just this, however, you have the ability to crawl your website and save out static copies and have them served up in place of the dynamic ones. For example, the ObjJob list of Properties takes almost 10 seconds for Haml to create the 450k of code, but it is served immediately from a disk-based static copy on the server.

net.mind details contact résumé other