Ruby on rails 代理背后的Rails3应用程序

Ruby on rails 代理背后的Rails3应用程序,ruby-on-rails,ruby,windows,apache2,reverse-proxy,Ruby On Rails,Ruby,Windows,Apache2,Reverse Proxy,我正在尝试在Apache2 Web服务器后面设置一个Rails 3应用程序,该服务器充当代理。 ApacheWebServer正在端口8080上运行,如果我调用,我会在mongrel窗口中看到请求,因此代理会正确地将输入请求中继到mongrel服务器 但是,如果没有用户名,我的索引页将重定向到登录名。所以我做了以下调用:http://:8080/app,但是重定向到http:///session/new 而不是http:///app/sessio/new 我不确定apache是否配置不当,我更怀

我正在尝试在Apache2 Web服务器后面设置一个Rails 3应用程序,该服务器充当代理。 ApacheWebServer正在端口8080上运行,如果我调用,我会在mongrel窗口中看到请求,因此代理会正确地将输入请求中继到mongrel服务器

但是,如果没有用户名,我的索引页将重定向到登录名。所以我做了以下调用:http://:8080/app,但是重定向到http:///session/new 而不是http:///app/sessio/new 我不确定apache是否配置不当,我更怀疑Rails3

下面是我的apache对这个代理的配置,我的routes.rb文件和一些我为可能的ServerSE代理修复找到的代码,但它似乎不起作用

反向代理修复

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/
我还想说明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)

如果我直接浏览stylsheets,我可以看到它们。

我想你的问题是rails和rack默认假定根url为/not/app

您可以通过调整RailsRackconfig来修复此问题

有关如何执行此操作,请参见以下答案:

还要将其添加到environment.rb文件的顶部

ENV['RAILS_RELATIVE_URL_ROOT'] = "/app"

希望这能有所帮助。

我最终通过切换到Nginx前端而不是apache解决了这个问题。 配置起来容易多了,而且工作起来很有魅力

我在windows上对apache proxy做了一些研究,发现了几个页面,其中描述了类似的问题,并提到了关于某个.so文件的bug。
我最终放弃了这一点,使用了nginx,下面是我如何使用子URI在apache2代理背后建立ror3应用程序的

首先,我使用webrick将应用程序设置为在子URI中运行,从而生成以下URL:

http://localhost:3000/myapp  
在config/environment.rb中,我添加了以下行:

ENV['RAILS_RELATIVE_URL_ROOT'] = "/myapp"
run Myapp::Application
接下来在config.ru中,我更改了以下行:

ENV['RAILS_RELATIVE_URL_ROOT'] = "/myapp"
run Myapp::Application
致:

启动webrick并将我的浏览器指向以下URL以确保其正常工作:

http://localhost:3000/myapp
配置了apachenext。已启用代理和代理\u 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

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

我已经在config.ru中添加了添加的内容,现在我收到了视图等,但是css和图像仍然缺失。但是,如果我直接浏览文件,我可以看到它们。@NekoNova-我已经编辑了我的答案,包括更改相对根url,这将对齐css和js资产路径。恐怕没有任何区别。应用程序在/app子目录中的localhost上运行良好,但是当通过代理传递内容时,css等不会加载更新:即使在localhost上,我现在也缺少样式表。您是否从应用程序中删除了反向代理修复代码?如果不是,我还建议您查看浏览器源代码,查看rails请求css、js等的路径,并根据需要进行调整。在上添加
ProxyPreserveHost解决了这个问题。我知道这已经5年了,但要小心
上的
ProxyRequests与所有的
Allow混用,我刚刚了解到这一点,但它似乎会导致一种情况!
http://www.example.com/myapp