RoR3 redirects not including RAILS_RELATIVE_URL_ROOT

On my public Apache2 server, access to my Rails 3 application is through a sub-URI, for example

https://www.myserver.com/myapp/controller... 

this server is configured for a reverse proxy to another Apache2 server on which the Rails application is installed through Passenger:

 http://intranet.server.com/myapp 

In my VirtualHost settings for the intranet server, I have

 SetEnv RAILS_RELATIVE_URL_ROOT "/myapp" 

In my config / environment / production.rb file, I uncommented the line

 config.log_level = :debug 

So the very first execution method in my application:

 logger.debug { "The environment variable RAILS_RELATIVE_URL_ROOT is presently #{ENV['RAILS_RELATIVE_URL_ROOT']}" } 

and, of course, in the production log file you will see:

 The environment variable RAILS_RELATIVE_URL_ROOT is presently /myapp 

However, the following line in the log is obviously the browser:

 Redirected to https://www.myserver.com/controller/action 

I found out about this environment variable here on Stackoverflow, so one person for whom it worked, but the other person hit by it didn’t know what another said. So, in my experience, we are now on a tie. Did I miss something?

+4
source share
4 answers

I understood my mistake. The reverse proxy settings on the external server referred only to the host name of the internal server and left the path to my RoR3 application.

0
source

As far as I know, the ability to use ENV var directly has been changed quite a while ago:

https://rails.lighthouseapp.com/projects/8994/tickets/1946-setting-a-relative-root-url-via-a-web-server-not-possible-anymore

So, in environment.rb (or the initializer) you can set config.action_controller.relative_url_root = ENV ['RAILS_RELATIVE_URL_ROOT']

+1
source

Wow, thanks a lot, I finally figured it out.

It seems that we need to make a proxy for the exact relative URL on the target rails :, the same uri match on apache.

eg: http://localhost/example/ to http://localhost:3000/example/

The following example has been tested on Rails 4:

therefore, in the proxy httpd.conf:

ProxyRequests Off
ProxyPreserveHost on
<Proxy *>
Cancel the order, allow Allow from all </ Proxy>

ProxyPass / example http: // localhost: 3000 / example

ProxyPassReverse / example http: // localhost: 3000 / example

Then further in rails config.ru:

require :: File.expand_path ('../config/environment', FILE )
#run Rails.application
map ActionController :: Base.config.relative_url_root do
run Examplerails :: Application
end

map "/" do
run Examplails :: Application
end

Finally, in config / application.rb

examplerails module
class Application <
Rails :: Application config.action_controller.relative_url_root = "/ example "
end
end

Pay close attention to trailing.
Some have slashes, while others don't need it. Also remove the gap between the tag and url in this code above,
im trying to format it for display here.

+1
source

I found this thread on Rails Github useful: https://github.com/rails/rails/issues/5122

I ended up doing the following in config / routes (I set relative_url_root via the RAILS_RELATIVE_URL_ROOT environment variable):

 Rails.application.routes.draw do |*args| scope Rails.application.config.relative_url_root || "/" do ... end end 
0
source

Source: https://habr.com/ru/post/1338346/


All Articles