title: Rails3 application behind a Proxy
body: <p>I'm trying to setup a Rails 3 application behind an Apache2 webserver which is acting as a proxy.
  The Apache webserver is running on port 8080, and if I make a call to the <a href="http://ip:8080">http://ip:8080</a>, I see the request in the mongrel window, so the proxy properly relays the incomming requests to the mongrel servers.</p>
  
  <p>However, my index page performs a redirect to the login if no username exists. So i make the following call : http://:8080/app , but the redirect goes to http:///session/new instead of http:///app/sessio/new
  i'm not really sure that the apache is badly configured, i'm more doubting about rails 3.</p>
  
  <p>Below is the config of my apache for this proxy stuff, my routes.rb file and some code I found for a potential rverse proxy fix, but it doesn't seem to work.</p>
  
  <p>REVERSE_PROXY_FIX</p>
  
  <pre><code>BASE_URL = ''
  module ActionController
    ActionController::Base.asset_host= BASE_URL
  
    class UrlRewriter
  #    alias old_rewrite_url rewrite_url
  
      # Prepends the BASE_URL to all of the URL requests created by the
      # URL rewriter in Rails.
      def rewrite_url(path, options)
        url = old_rewrite_url(path, options)
        url = url.gsub(@request.protocol + @request.host_with_port, '')
        url = BASE_URL + url
        url
      end
    end
  end 
  </code></pre>
  
  <p>Apache2 config</p>
  
  <pre><code># This file contains the proxy settings for apache to map all the incomming requests for a specific application to the relevant mongrel
  # web server that is able to handle the incoming requests.
  LoadModule proxy_module modules/mod_proxy.so
  LoadModule proxy_http_module modules/mod_proxy_http.so
  ProxyRequests Off
  
  &lt;Proxy *&gt;
      Order deny,allow
      Allow from all
  &lt;/Proxy&gt;
  
  
  # The section below tells Apache where to find all the static files for our applications.
  # Because these settings are application specific, we need to create entries for each application
  # that we wish to run under the Apache &amp; Mongrel configuration
  Alias /Esco "c:/web/esco/public"
  &lt;Directory "C:/web/esco/public"&gt;
      Options Indexes FollowSymLinks
      AllowOverride none
      Order allow,deny
      Allow from all
  &lt;/Directory&gt;
  
  ProxyPass /Esco/images !
  ProxyPass /Esco/stylesheets !
  ProxyPass /Esco/javascripts !
  ProxyPass /Esco/ http://127.0.0.1:4000/
  ProxyPass /Esco http://127.0.0.1:4000/
  ProxyPassReverse /Esco/ http://127.0.0.1:4000/
  </code></pre>
  
  <p>routes.rb</p>
  
  <pre><code>ESCO::Application.routes.draw do
    root :to =&gt; 'static#index'
    resources :cvs
    match 'cvs/match' =&gt; 'cvs#match', :as =&gt; :match_resume, :via =&gt; :post
  
      # Session Routes
    # These routes are for logging in and out from the application.
    match 'session/new' =&gt; 'session#new', :as =&gt; :new_session, :via =&gt; :get
    match 'session/create' =&gt; 'session#create', :as =&gt; :create_session, :via =&gt; :put
    match 'session/destroy' =&gt; 'session#destroy', :as =&gt; :destroy_session, :via =&gt; :delete
  
    # Admin panel Routers
    # These routes are for managing all the entities currently residing in the application
    match 'admin' =&gt; 'admin/static#index', :as =&gt; :admin_index, :via =&gt; :get
    match 'admin/cvs/save' =&gt; 'admin/cvs#save', :as =&gt; :admin_save_cv, :via =&gt; :post
    namespace "admin" do
      resources :users, :cvs, :settings, :languages, :vacancies, :countries, :languages
    end
  end
  </code></pre>
  
  <p>I also like to mnetion that the apache is running on a Windows Server 2008R2 x64 system, and that the rails applications are running inside a Mongrel server on the same system ranging from port 4000 -> 4010.
  I hope someone can help me sort this reverse proxy thing.</p>
  
  <p><strong>EDIT</strong>:
  I've updated the config.ru file to run the application from the same subfolder domain as the proxy would do, and that allows me to see the views etc, but still missing the stylesheets and images.</p>
  
  <p>Mongrel receives the following:</p>
  
  <pre><code>Started GET "/Esco/" for 81.82.197.2 at 2011-05-09 13:25:44 +0200
    Processing by StaticController#index as HTML
  Rendered static/index.html.haml within layouts/application (15.6ms)
  Completed 200 OK in 31ms (Views: 31.2ms | ActiveRecord: 0.0ms)
  </code></pre>
  
  <p>And if I browse to the stylsheets directly, I can see them.</p>