Thursday, July 5, 2012

integrate http reverse proxy cache server with Rails and Varnish



  • Setup Apache and make a virtual host to listen it on other port like 8080
  • Install varnish and listens it on port 80
  • For the Varnish, you need to do configuration on two files like bellow





Here is the requesting flow: Browser ---> Varnish---->Apache2----->Application Server
That means, when u request through browser, it request to Varnish(on port 80) and if varnish has cached then it served directly to client(browser) without interfering apache otherwise Varnish passes the request to apache...In this way you can scale your Rails app heavily and serve a lot of requests concurrently with low memory and low resource consumed.

Some varnish useful commands:
  • Restart Varnish - /etc/init.d/varnish restart
  • Show Varnish statistics - varnishstat
  • Test to see response is coming through Varnish -
    curl -I http://www.your_app_url.com