代理后面的Rails3应用程序
我正在尝试在充当代理的Apache2 webserver后面安装Rails 3应用程序。 Apache网络服务器在端口8080上运行,如果我拨打http://ip:8080,我会在混合窗口中看到该请求,因此代理会正确地将发送请求中继到混合服务器。代理后面的Rails3应用程序
但是,如果不存在用户名,我的索引页将执行重定向到登录。所以我打出以下电话:http://:8080/app,但重定向转到http:/// session/new而不是http:/// app/sessio/new 我不太确定apache配置错误,我更怀疑rails 3.
下面是我的apache代理配置文件,我的routes.rb文件和一些代码,我发现一个潜在的横向代理修复,但它doesn似乎没有用。
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配置
# 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
我也喜欢mnetion的Apache是在Windows Server 2008 R2 x64系统上运行,并且轨道应用程序在端口400范围内的同一系统上的Mongrel服务器中运行0 - > 4010. 我希望有人能帮我分类这个反向代理的东西。
编辑: 我已经更新了config.ru文件运行从同一子域的代理会做的应用程序,这让我看到了意见等,但仍不失其样式表和图像。
杂种收到以下:
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)
如果我直接浏览到stylsheets,我可以看到他们。
我终于通过切换到Nginx前端而不是apache来解决问题。 更容易配置和像魅力一样工作。
我已经做了一些在Windows上的Apache代理的研究,并发现了几个页面的类似问题beeing描述和错误提到关于某个.so文件。 我终于放弃了这个和使用nginx的
我觉得你的问题是,导轨和机架默认假定根网址是/不是/应用
您可以通过调整你的Rails 机架配置解决这个问题。
参见如何做到这一点这样的回答:Changing the base URL for Rails 3 development
也添加到您的environment.rb文件中
ENV['RAILS_RELATIVE_URL_ROOT'] = "/app"
希望这有助于顶部。
这里是我后面成立了Apache 2的代理一个回报率3应用程序使用子URI。
首先,我设置该应用使用导致以下URL的WEBrick在子URI来运行:
http://localhost:3000/myapp
在配置/ environment.rb中我添加下列行:
ENV['RAILS_RELATIVE_URL_ROOT'] = "/myapp"
接着在config.ru我改变下列行:
run Myapp::Application
到:
map '/myapp' do
run Myapp::Application
end
开始使用WEBrick,并指出我的浏览器访问以下网址,以确保它的工作原理:
http://localhost:3000/myapp
配置了Apache未来。启用了proxy和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
所有链接和重定向工作。
我已经在config.ru添加了东西,现在我收到的意见等,但CSS和图像仍然失踪。如果我直接浏览文件,我可以看到它们。 – 2011-05-09 11:33:01
@NekoNova - 我编辑了我的答案,包括更改将调整CSS和js资源路径的relative_root_url。 – 2011-05-09 11:57:21
我不害怕。应用程序运行上的/ app子目录本地主机,但传送的东西通过代理服务器时,CSS等未装入 – 2011-05-09 12:05:23