加入收藏 | 设为首页 | 会员中心 | 我要投稿 李大同 (https://www.lidatong.com.cn/)- 科技、建站、经验、云计算、5G、大数据,站长网!
当前位置: 首页 > 百科 > 正文

ruby-on-rails – 代理后面的Rails3应用程序

发布时间:2020-12-17 03:27:31 所属栏目:百科 来源:网络整理
导读:我正在尝试在作为代理的Apache2网络服务器后面设置一个Rails 3应用程序. Apache Web服务器在端口8080上运行,如果我调用 http://ip:8080,我在mongrel窗口中看到请求,因此代理正确地将接收请求中继到mongrel服务器. 但是,如果没有用户名,我的索引页将执行重定
我正在尝试在作为代理的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

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

我还想知道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)

如果我直接浏览样式表,我可以看到它们.

解决方法

以下是我如何使用子URI在Apache 2代理后面设置RoR 3应用程序.

首先,我使用webrick将应用程序设置为在子URI中运行,从而产生以下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和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

所有链接和重定向都有效.

(编辑:李大同)

【声明】本站内容均来自网络,其相关言论仅代表作者个人观点,不代表本站立场。若无意侵犯到您的权利,请及时与联系站长删除相关内容!

    推荐文章
      热点阅读