问题
After failed attempts with Passenger (see my other question), I managed to get rails running via a reverse proxy in a subfolder. I added the lines
config.relative_url_root = "/App"
config.action_controller.relative_url_root = "/App"
to my environment. Now I can access my rails project under www.mySite.com/App. The problem is that the links /paths dont add the prefix "/App". So a link to "users" looks like
www.mySite.com/users
instead of www.mySite.com/App/users
.
How can I change this?
At least according to http://edgeguides.rubyonrails.org/configuring.html#deploy-to-a-subdirectory-relative-url-root I did everything correct.
回答1:
I got it working by adjusting my reverse proxy and my rails config as follows. This is my corresponding apache file:
<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>
My config.ru looks like this:
require ::File.expand_path('../config/environment', __FILE__)
map '/App' do
run Rails.application
end
The mentioned environments variables are set in /config/environment.rb. I am not sure if they are still needed:
config.relative_url_root = "/App"
config.action_controller.relative_url_root = "/App"
ENV['RAILS_RELATIVE_URL_ROOT'] = "/App"
ENV['ROOT_URL'] = "/App"
回答2:
In Rails 4.2, I had the same need and resolved modifying some configuration files. Routes.rb:
Rails.application.routes.draw do
scope :mytm do
....
end
end
This do not require any modification to the application.
Furthermore, you have to reconfigure the asset pipeline, in /config/initializers/assets.rb:
Rails.application.config.assets.prefix = "/app/asset"
....
回答3:
I'm not entirely sure if I understand what you're trying to do, but I think what you're describing is essentially namespacing all of your controllers under "/App"
or something like that. This would be in your routes.rb
file:
namespace "App" do
# Put your resources here, as however you defined them before, e.g.:
resources :users, :decks, :cards, :revs, :sessions
end
来源:https://stackoverflow.com/questions/27761278/rails-relative-url-doesnt-adjust-links