Rails3 application behind the proxy server

I am trying to configure a Rails 3 application behind an Apache2 web server, which acts as a proxy. The Apache web server runs on port 8080, and if I make a call to http: // ip: 8080 , I see the request in the mongrel window, so the proxy server correctly sends incoming requests to the mongrel servers.

However, my index page redirects to login if the username does not exist. So I make the following call: http: //: 8080 / app, but the redirection goes to http: /// session / new instead of http: /// app / sessio / new I'm not sure that apache is configured poorly, I doubt it more in rails 3.

Below is the configuration of my apache for this proxy file, my route.rb file and some code that I found for a potential proxy fix, but it does not seem to work.

REVERSE_PROXY_FIX

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 

Apache2 config

# 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

<Proxy *>
    Order deny,allow
    Allow from all
</Proxy>


# 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 & Mongrel configuration
Alias /Esco "c:/web/esco/public"
<Directory "C:/web/esco/public">
    Options Indexes FollowSymLinks
    AllowOverride none
    Order allow,deny
    Allow from all
</Directory>

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/

routes.rb

ESCO::Application.routes.draw do
  root :to => 'static#index'
  resources :cvs
  match 'cvs/match' => 'cvs#match', :as => :match_resume, :via => :post

    # Session Routes
  # These routes are for logging in and out from the application.
  match 'session/new' => 'session#new', :as => :new_session, :via => :get
  match 'session/create' => 'session#create', :as => :create_session, :via => :put
  match 'session/destroy' => 'session#destroy', :as => :destroy_session, :via => :delete

  # Admin panel Routers
  # These routes are for managing all the entities currently residing in the application
  match 'admin' => 'admin/static#index', :as => :admin_index, :via => :get
  match 'admin/cvs/save' => 'admin/cvs#save', :as => :admin_save_cv, :via => :post
  namespace "admin" do
    resources :users, :cvs, :settings, :languages, :vacancies, :countries, :languages
  end
end

I also like mnetion that apache works on a Windows Server 2008R2 x64 system and that rails applications run inside a Mongrel server on the same system starting from port 4000 β†’ 4010. I hope someone can help me sort this reverse proxy server .

EDIT : I updated the config.ru file to run the application from the same subfolder domain as the proxy, and this allows me to view views, etc., but at the same time there are not enough stylesheets and images.

Mongrel gets the following:

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)

And if I go directly to the styles, I will see them.

+5
3

, , , Nginx apache. .

- apache , , , .so . , , nginx

0

RoR 3 - Apache 2, -URI.

URI webrick, URL-:

http://localhost:3000/myapp  

config/environment.rb :

ENV['RAILS_RELATIVE_URL_ROOT'] = "/myapp"

config.ru :

run Myapp::Application

map '/myapp' do
  run Myapp::Application
end

webrick URL-, , :

http://localhost:3000/myapp

Apache. proxy_http. proxy.conf:

ProxyRequests On
<Proxy *>
    AddDefaultCharset off        Order deny,allow
    Allow from all
    #Allow from .example.com
</Proxy>

ProxyPass /myapp http://localhost:3000/myapp
ProxyPassReverse /myapp http://localhost:3000/myapp

Apache :

http://www.example.com/myapp

.

+7

, , , URL- is/not/app

, Rails Rack.

. , : URL- Rails 3

environment.rb

ENV['RAILS_RELATIVE_URL_ROOT'] = "/app"

, .

0

All Articles