在Apache下的子目录中配置Ruby On Rails App

时间:2009-01-22 21:49:41

标签: ruby-on-rails ruby apache2 windows-server-2003

我在Windows上有apache2.2。我正在尝试同时提供subversion(/ svn)和redmine(/ redmine)。我用这个配置运行svn很好:

<Location /svn>
  DAV svn
  SVNParentPath C:/svn_repository
  ...
</Location>

这很有效 - 我的svn用户可以点击http://mybox/svn就好了。

现在我想为rails app(RedMine)添加另一个目录:

我按照this question中的建议设置了一个mongrel服务器并拥有apache代理客户端。如果我把它作为根目录,它可以正常工作 - 但我在子目录中制作它时遇到了麻烦:

<Location /redmine>
  ProxyPass http://localhost:3000/
  ProxyPassReverse http://localhost:3000/
</Location>

有什么建议吗?

4 个答案:

答案 0 :(得分:15)

以下是我必须改变的内容:

我删除了尾部斜杠:

<Location /redmine>
  ProxyPass http://localhost:3000
  ProxyPassReverse http://localhost:3000/
</Location>

在我的应用程序中:

# added to end of file C:\redmine\config\environment.rb
ActionController::AbstractRequest.relative_url_root = "/redmine"

现在它正在运作!


我对这种方法并不完全满意 - 我遇到了一些重定向问题。这是迄今为止似乎运作良好的另一种尝试。

第二种方法似乎更好。


<强>更新

正如评论中所述,对于在Rails 2.3.2+上运行的最新应用,请改用:

config.action_controller.relative_url_root = '/redmine'

我把它放在新的additional_environment.rb文件中。

答案 1 :(得分:1)

如果您仍然希望使用反向代理使用Mongrel + Apache,我是如何在我们的系统上解决相同的问题(Win2k3,Apache 2.2,Redmine的主干)。秘诀是使用--prefix /redmine安装您的杂种服务,告诉它从http://localhost:port/redmine

提供服务

在Apache httpd.conf(或合适的包含文件)中:

LoadModule proxy_module modules/mod_proxy.so
LoadModule proxy_http_module modules/mod_proxy_http.so

<IfModule mod_proxy.c>
ProxyRequests Off
#No need to forward on static content - let apache do it faster
ProxyPass /redmine/images ! 
ProxyPass /redmine/stylesheets ! 
ProxyPass /redmine/javascript ! 
# Remove the following entry on public sites as this is insecure
ProxyPass /redmine/plugin_assets !
ProxyPass /redmine/help ! 
ProxyPass /redmine http://localhost:4000/redmine
ProxyPassReverse /redmine http://localhost:4000/redmine
ProxyPreserveHost On
#continue with other static files that should be served by apache
Alias /redmine/images C:/Repositories/redmine/public/images/
Alias /redmine/stylesheets C:/Repositories/redmine/public/stylesheets/
Alias /redmine/javascript C:/Repositories/redmine/public/javascript/
# Remove the following on public sites as this is insecure
Alias /redmine/plugin_assets C:/Repositories/redmine/public/plugin_assets/
Alias /redmine/help C:/Repositories/redmine/public/help/
</IfModule>

# Make sure apache can see public and all subfolders - not suitable for public sites
<Directory "C:/Repositories/redmine/public/">
    Allow from all
    Order allow,deny
</Directory>

Mongrel安装如下:

mongrel_rails service::install --prefix /redmine -N redmine_prod -p 4000 -e production -c C:\Repositories\redmine

希望有人帮助。最初,我尝试设置Apache + fastcgi等,但我失去了更多珍贵的头发 - 它不是Windows友好的。

P.S。我发现这个PDF非常有用:http://www.napcsweb.com/howto/rails/deployment/RailsWithApacheAndMongrel.pdf

/达明

答案 2 :(得分:0)

Passenger(http://modrails.com)是fastcgi的更好替代方案,因为它非常容易配置我建议使用这个来使用与现在类似的配置来托管rails应用程序

答案 3 :(得分:0)

我同意雷达。 Passenger非常容易设置,让Rails应用程序共享内存,消除了管理一组mongrel的负担,几乎不需要任何配置。您只需要一个特殊的'config.ru'文件,其中RackUp config和一个DocumentRoot指向Apache中的RAILS_ROOT / public。

相关问题