Last Updated: February 25, 2016
·
5.546K
· andy_kif

Set up a Rack reverse proxy for Rails or Sinatra or any Rack based stack

We use most of the time used to do reverse proxy from Apache or Nginx front-end server.

Until recently, I didn't knew that we can do it also with Rack.

Why ?

Imagine you have to migrate static pages from your rails app to another host, like what happens for Codeship in this post who decided to migrate their documentation on Amazon S3.

How ?

By just 4 lines of codes in your config.ru

require 'rack/reverse_proxy'

use Rack::ReverseProxy do
  reverse_proxy /^\/documentation\/?(.*)$/, 'http://path-to-your-host/$1'
end

$1 is the path of the page extracted from original url

Everytime anyone points to /documentation, your rails app serves back static content from the static pages host, smart right ?

I'm sure I'll use this technique for my upcoming SaaS !

1 Response
Add your response

Neat :-)

over 1 year ago ·