2015-01-04 13 views
5

Passenger嘗試失敗後(請參閱我的其他問題),我設法讓rails通過子文件夾中的反向代理運行。 我添加了行Rails relative_url不調整鏈接

config.relative_url_root = "/App" 
config.action_controller.relative_url_root = "/App" 

到我的環境。現在我可以通過www.mySite.com/App訪問我的rails項目。問題是鏈接/路徑不添加前綴「/ App」。所以到「用戶」的鏈接看起來像 www.mySite.com/users而不是www.mySite.com/App/users。 我該如何改變這一點?

至少根據http://edgeguides.rubyonrails.org/configuring.html#deploy-to-a-subdirectory-relative-url-root我做了一切正確。

+0

你能在你的終端運行'耙routes'並張貼在這裏的輸出? –

+0

這裏是 http://pastebin.com/XWEjRZsi – yell

回答

3

我把它調整我的反向代理和我的rails配置如下工作。 這是我的Apache相應的文件:

<VirtualHost *:80> 
DocumentRoot /path/to/App/public 
ProxyPass /App http://127.0.0.1:9292/App 
ProxyPassReverse /App http://127.0.0.1:9292/App 
</VirtualHost> 

我config.ru看起來是這樣的:

require ::File.expand_path('../config/environment', __FILE__) 
map '/App' do 
    run Rails.application 
end 

變量在/config/environment.rb設置的提到的環境。我不知道他們是否仍然需要:

config.relative_url_root = "/App" 
config.action_controller.relative_url_root = "/App" 
ENV['RAILS_RELATIVE_URL_ROOT'] = "/App" 
ENV['ROOT_URL'] = "/App" 
+0

感謝您的支持。你有沒有想出最佳配置?我的資產URL很好,但鏈接沒有被子應用程序作爲前綴,所以我遇到了同樣的問題。我正在和Puma一起使用nginx。 – danebez

+0

我嘗試了幾種基於給定解決方案的配置。我發現了兩個最小的解決方案:無論是config.relative_url_root =「/ App」還是config.action_controller.relative_url_root =「/ App」。文件config.ru必須修改... 。使用環境變量,我可以訪問頁面,但資源(圖像,js和css)未處理... – user1251840

0

我不完全確定,如果我明白你想要做什麼,但我認爲你所描述的基本上是命名空間的所有控制器在"/App"或類似的東西。這將是您的routes.rb文件:

namespace "App" do 

    # Put your resources here, as however you defined them before, e.g.: 
    resources :users, :decks, :cards, :revs, :sessions 

end 
+1

我以前試過,這樣做會導致'App /用戶不是受支持的控制器' – yell

0

在Rails 4.2中,我有同樣的需求並解決了修改某些配置文件。 Routes.rb:

Rails.application.routes.draw do 
    scope :mytm do 
    .... 
    end 
end 

這不需要對應用程序進行任何修改。

此外,你必須重新配置資產的管道,在/config/initializers/assets.rb:

Rails.application.config.assets.prefix = "/app/asset" 
    ....