如何在子目录中部署Rails 3.1 app

如何配置Rails 3.1应用程序在特定目录(如“/ r”)下运行?

我试过在config.ru:

map '/r' do run Debtor::Application end 

但刚刚返回“未找到:/ r”

为了使它工作,我必须将所有路由包含在范围内:

 scope '/r' do #routes end 

并将以下行添加到config / applcation.rb

 config.assets.prefix = "/r/assets" 

并将我的jquery ui css文件从/ stylesheets移动到/ r / stylesheets。

这似乎太复杂了。 是不是有更简单的方法? 为什么我的config.ru设置不起作用?

我的用例是为wordpress服务器安装一个有轨的电源ajax后端。

你在乘客下跑吗?

那么RailsBaseURI可能就是你想要的。

https://www.phusionpassenger.com/library/deploy/apache/deploy/ruby/#deploying-an-app-to-a-sub-uri

如果没有在乘客下运行,请更新您的问题以显示您的部署情况。

对我有用的是为子uri(/ info)创建应用程序的’public’文件夹的符号链接(在我的服务器上的另一个用户下设置,/ home / otheruser / current / public)。

 ln -s /home/myapp/current/public /home/mysite/public_html/info 

然后我将此配置插入到站点的VirtualHost条目中:

 Alias /info /home/myapp/current/public  PassengerAppRoot /home/myapp/current RackEnv production RackBaseURI /info  

没有作用域路由,没有资产前缀配置。

以下是如何将Rails 3.1应用程序部署到Apache中的子目录,替换不再存在的config.action_controller.relative_url_root

config/routes.rb

 scope 'my_subdir' do # all resources and routes go here end 

在Apache配置文件中:

 Alias /my_subdir /var/www/my_subdir/public  SetEnv RAILS_RELATIVE_URL_ROOT "/my_subdir" PassengerAppRoot /var/www/my_subdir  

它应该工作,包括自动将所有资产指向/my_subdir