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 !
Written by Andy Kifer
Related protips
1 Response
Neat :-)
over 1 year ago
·
Have a fresh tip? Share with Coderwall community!
Post
Post a tip
Best
#Rails
Authors
Sponsored by #native_company# — Learn More
#native_title#
#native_desc#