From 2d8de78e9a4c22bf1339f0bbd77a4145df0b229f Mon Sep 17 00:00:00 2001 From: Pankaj Tyagi Date: Thu, 11 Oct 2012 15:37:14 -0300 Subject: [PATCH] Added documentation for Rails 3 MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Rails 3 approach is documented.  The other approach will work in Rails 3 but not in JRuby using warbler.  If the Rails middleware configuration standard is used it works in all forms of ruby and servers. --- README.rdoc | 31 +++++++++++++++++++++++++++++++ 1 file changed, 31 insertions(+) diff --git a/README.rdoc b/README.rdoc index be1f0ad..22a45ec 100644 --- a/README.rdoc +++ b/README.rdoc @@ -14,6 +14,7 @@ Matchers can be a regex or a string. If a regex is used, you can use the subcap Right now if more than one matcher matches any given route, it throws an exception for an ambiguous match. This will probably change later. If no match is found, the call is forwarded to your application. +=== Configuring for a Rack app Below is an example for configuring the middleware: require 'rack/reverse_proxy' @@ -34,6 +35,36 @@ Below is an example for configuring the middleware: end run app +=== Configuring for Rails 3 +In your application.rb add the middleware configuration as below: + + module MyApp + class Application < Rails::Application + # Settings in config/environments/* take precedence over those specified here. + # Application configuration should go into files in config/initializers + # -- all .rb files in that directory are automatically loaded. + + # ... + + # add reverse-proxy middleware + # reverse proxy middle ware + require 'rack/reverse_proxy' + + config.middleware.use Rack::ReverseProxy do + # Set :preserve_host to true globally (default is true already) + reverse_proxy_options :preserve_host => true + + # Forward the path /test* to http://example.com/test* + reverse_proxy '/test', 'http://example.com/' + + # Forward the path /foo/* to http://example.com/bar/* + reverse_proxy /^\/foo(\/.*)$/, 'http://example.com/bar$1', :username => 'name', :password => 'basic_auth_secret' + end + + end + end + +=== Options reverse_proxy_options sets global options for all reverse proxies. Available options are: * :preserve_host Set to false to omit Host headers * :username username for basic auth