cod*_*nny 5 ruby windows reverse-proxy ruby-on-rails apache2
我正在尝试在作为代理的Apache2网络服务器后面设置一个Rails 3应用程序.Apache Web服务器在端口8080上运行,如果我调用http:// ip:8080,我在mongrel窗口中看到请求,因此代理正确地将接收请求中继到mongrel服务器.
但是,如果没有用户名,我的索引页将执行重定向到登录.所以我做了以下调用:http://:8080/app,但重定向转到http:/// session/new而不是http:/// app/sessio/new我不是很确定apache配置不当,我更担心rails 3.
下面是我的apache配置这个代理的东西,我的routes.rb文件和我发现的潜在的反向代理修复的一些代码,但它似乎不起作用.
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
Run Code Online (Sandbox Code Playgroud)
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/
Run Code Online (Sandbox Code Playgroud)
的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
Run Code Online (Sandbox Code Playgroud)
我还想知道apache正在Windows Server 2008R2 x64系统上运行,并且rails应用程序在同一系统上的Mongrel服务器内运行,范围从端口4000 - > 4010.我希望有人可以帮助我对此进行排序代理的东西.
编辑:我已经更新了config.ru文件,以便从代理将执行的相同子文件夹域运行应用程序,这允许我查看视图等,但仍然缺少样式表和图像.
Mongrel收到以下内容:
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)
Run Code Online (Sandbox Code Playgroud)
如果我直接浏览样式表,我可以看到它们.
小智 7
以下是我如何使用子URI在Apache 2代理后面设置RoR 3应用程序.
首先,我使用webrick将应用程序设置为在子URI中运行,从而产生以下URL:
http://localhost:3000/myapp
Run Code Online (Sandbox Code Playgroud)
在config/environment.rb中,我添加了以下行:
ENV['RAILS_RELATIVE_URL_ROOT'] = "/myapp"
Run Code Online (Sandbox Code Playgroud)
接下来在config.ru中我更改了以下行:
run Myapp::Application
Run Code Online (Sandbox Code Playgroud)
至:
map '/myapp' do
run Myapp::Application
end
Run Code Online (Sandbox Code Playgroud)
启动webrick并将浏览器指向以下URL以确保其有效:
http://localhost:3000/myapp
Run Code Online (Sandbox Code Playgroud)
接下来配置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
Run Code Online (Sandbox Code Playgroud)
重启Apache和我的应用程序可在以下位置获得:
http://www.example.com/myapp
Run Code Online (Sandbox Code Playgroud)
所有链接和重定向都有效.
我最终通过切换到 Nginx 前端而不是 apache 解决了这个问题。配置更容易并且工作起来就像一个魅力。
我对 Windows 上的 apache 代理做了一些研究,发现几个页面描述了类似的问题,并提到了有关某个 .so 文件的错误。我最终放弃了这个并使用了nginx
| 归档时间: |
|
| 查看次数: |
5273 次 |
| 最近记录: |