Defect #12102
openInstalled Redmine in a sub-URI: Links are generated not correctly
Added by Dmitry Vorobiev about 12 years ago. Updated almost 4 years ago.
0%
Description
I have Redmine app installed in a sub-URI on Apache server (configured as Alias/ProxyPass, the same way as working installation of Redmine 0.8.5).
New installed Redmine app render pages correctly (both start or any inner page launched by direct URL like "/redmine2/issues/4600", where 4600 is a number of existing ticket) but has inner navigation links without sub-URI ("redmine2" in my case):
i.e. links are http://mydomain/projects instead of http://mydomain/redmine2/projects
My changes in configuration files are (based on advices given in issue #11881 etc):
# File: config/environment.rb
# Initialize the rails application
RedmineApp::Application.initialize!
Redmine::Utils::relative_url_root = "/redmine2"
Please note that suggestion with RedmineApp::Application.routes.default_scope
is not working for me (it gives rendered page with text "Page not found // The page you were trying to access doesn't exist or has been removed."):
# File: config/environment.rb
# NOT WORKED FOR ME:
# RedmineApp::Application.routes.default_scope = { :path => '/redmine2', :shallow_path => '/redmine2' }
Environment:
Redmine version 2.1.2
Ruby version 1.9.3
Rails version 3.2.8
Environment production
Database adapter MySQL
Operating system Microsoft Windows Server 2003 [Version 5.2.3790]
Files
redmine_wrong_urls.png (6.12 KB) redmine_wrong_urls.png | Dmitry Vorobiev, 2012-10-15 15:38 | ||
2012-10-16_073110.png (3.37 KB) 2012-10-16_073110.png | Dmitry Vorobiev, 2012-10-16 05:37 | ||
2012-10-16_073318.png (5.48 KB) 2012-10-16_073318.png | Dmitry Vorobiev, 2012-10-16 05:37 | ||
2012-10-16_073308.png (6.25 KB) 2012-10-16_073308.png | Dmitry Vorobiev, 2012-10-16 05:37 | ||
routes_16102012_739.txt (49.6 KB) routes_16102012_739.txt | Dmitry Vorobiev, 2012-10-16 05:40 |
Related issues
Updated by Etienne Massip about 12 years ago
You should insert it before the initialize, not replace the whole file contents.
# File: config/environment.rb
# Initialize the rails application
RedmineApp::Application.routes.default_scope = { :path => '/redmine2', :shallow_path => '/redmine2' }
RedmineApp::Application.initialize!
Redmine::Utils::relative_url_root = "/redmine2"
My 2 cents :
Redmine::Utils::relative_url_root
should be deprecated, it only affects static assets URLs and we should promoteconfig.asset_path = "/redmine2%s"
inapplication.rb
insteadconfig.serve_static_assets
should be explicitely set to false inenvironment/production.rb
(it is for a brand new generated Rails app). This would deactivateActionDispatch::Static
middleware which is meant for development mode use only and would prevent issues such as this one
Updated by Dmitry Vorobiev about 12 years ago
- File 2012-10-16_073110.png 2012-10-16_073110.png added
- File 2012-10-16_073318.png 2012-10-16_073318.png added
- File 2012-10-16_073308.png 2012-10-16_073308.png added
Etienne, thank you for quick response!
First of all, about RedmineApp::Application.routes.default_scope - as I wrote in the issue:
Please note that suggestion with
RedmineApp::Application.routes.default_scope
is not working for me (it gives rendered page with text "Page not found // The page you were trying to access doesn't exist or has been removed.")
Sorry, may be my description was unclear but of course I tried to set Application.routes.default_scope
before calling initialize
. Let me illustrate the result:
File: config/environment.rb
Result for root and sample inner page (called by existing direct URL)
Stack trace for calling issue 4600:
Started GET "/issues/4600" for 127.0.0.1 at 2012-10-16 07:32:48 +0400 ActionController::RoutingError (No route matches [GET] "/issues/4600"): actionpack (3.2.8) lib/action_dispatch/middleware/debug_exceptions.rb:21:in `call' actionpack (3.2.8) lib/action_dispatch/middleware/show_exceptions.rb:56:in `call' railties (3.2.8) lib/rails/rack/logger.rb:26:in `call_app' railties (3.2.8) lib/rails/rack/logger.rb:16:in `call' actionpack (3.2.8) lib/action_dispatch/middleware/request_id.rb:22:in `call' rack (1.4.1) lib/rack/methodoverride.rb:21:in `call' rack (1.4.1) lib/rack/runtime.rb:17:in `call' activesupport (3.2.8) lib/active_support/cache/strategy/local_cache.rb:72:in `call' rack (1.4.1) lib/rack/lock.rb:15:in `call' actionpack (3.2.8) lib/action_dispatch/middleware/static.rb:62:in `call' rack-cache (1.2) lib/rack/cache/context.rb:136:in `forward' rack-cache (1.2) lib/rack/cache/context.rb:245:in `fetch' rack-cache (1.2) lib/rack/cache/context.rb:185:in `lookup' rack-cache (1.2) lib/rack/cache/context.rb:66:in `call!' rack-cache (1.2) lib/rack/cache/context.rb:51:in `call' railties (3.2.8) lib/rails/engine.rb:479:in `call' railties (3.2.8) lib/rails/application.rb:223:in `call' rack (1.4.1) lib/rack/content_length.rb:14:in `call' railties (3.2.8) lib/rails/rack/log_tailer.rb:17:in `call' rack (1.4.1) lib/rack/handler/webrick.rb:59:in `service' c:/Ruby193/lib/ruby/1.9.1/webrick/httpserver.rb:138:in `service' c:/Ruby193/lib/ruby/1.9.1/webrick/httpserver.rb:94:in `run' c:/Ruby193/lib/ruby/1.9.1/webrick/server.rb:191:in `block in start_thread'
Updated by Dmitry Vorobiev about 12 years ago
- File routes_16102012_739.txt routes_16102012_739.txt added
May be routes will be helpful (see attached file)
Updated by Etienne Massip about 12 years ago
If you're using ProxyPass then I guess that you're running a Rack Ruby application server, could you tell us which one and how it is configured?
Since rake routes
answers fine, there is no reason it generates wrong URLs…
Any plugin?
Last question for my knowledge, did you try with the following syntax:
RedmineApp::Application.routes.default_scope = '/redmine2'
It fails for shallow routes with FCGI but it should be ok with Rack servers.
Updated by Etienne Massip about 12 years ago
Oh, you're running Webrick.
In production, please don't, it is designed for development.
Updated by Dmitry Vorobiev about 12 years ago
Etienne Massip wrote:
Oh, you're running Webrick.
In production, please don't, it is designed for development.
In production with Redmine 0.8.5 we use Mongrel, now I'm trying to deploy (not replace existing production installation) new release 2.1.2 with Webrick (Mongrel also failed to work with actual Redmine due to Rails version as I understand).
Updated by Etienne Massip about 12 years ago
Because you're on Windows I'd suggest you to use Puma which runs fine for me.
It uses Mongrel parser BTW, this latter indeed being incompatible with latest Rails versions.
Updated by Dmitry Vorobiev about 12 years ago
Thank you, Etienne, I will try Puma and write here about results.
Etienne Massip wrote:
Last question for my knowledge, did you try with the following syntax:
RedmineApp::Application.routes.default_scope = '/redmine2'
Result is the same as for one with shallow_path ("Page not found").
Updated by Alex Muntada about 12 years ago
I'm getting 404 for all assets after setting this:
# File: config/environment.rb
# Initialize the rails application
RedmineApp::Application.routes.default_scope = { :path => '/redmine', :shallow_path => '/redmine' }
RedmineApp::Application.initialize!
Redmine::Utils::relative_url_root = "/redmine"
Note that rake routes RAILS_ENV=production
shows all URL with /redmine
and all page links are actually working under /redmine
, but no CSS nor JS files are being retrieved; they're actually under /
(e.g. http://localhost:3000/javascripts/prototype.js
). Should i file a new issue?
My environment is:
- redmine 2.0-stable via github (v2.0.4)
- ruby-1.9.3-p286 via rvm
- rails 3.2.6
- environment production
- server mongrel 1.2.0.pre2
- database adapter sqlite3
- operating system ubuntu
Updated by Etienne Massip about 12 years ago
No, first please get rid of Mongrel which is not maintained and is know to spell trouble with Rails 3 (and remove potential related patches you may have installed to make it work).
Also, related to #note-1:
- Serve your assets with a web server, don't use Rack server for this!
- I personally advise you to use
config.asset_path = "/redmine%s"
inapplication.rb
rather thanRedmine::Utils::relative_url_root
Dmitry K: did you fix your issue?
Updated by Alex Muntada about 12 years ago
Etienne,
i removed the vendor directory, removed mongrel from Gemfile.local and reinstalled all gems with bundle. Then, i got the same results with webrick, thin and puma. The config.asset_path
setting made no difference, which makes me wonder where the problem is.
I understand the need to serve assets from a web server but that shouldn't mean that they can't be served by Rack under /redmine
the same way they are being served under /
by default.
The fact is that i need to setup a reverse proxy in one server that uses another one as the backend running Redmine under /some/uri
and can't find a way to run Redmine outside /
. Is there any recommended and setup for Redmine outside /
? Passenger maybe?
Updated by Teddy L about 12 years ago
Working for me with the following configurations on 2.1-stable:
- in Apache
ProxyPass /redmine http://127.0.0.1:3000/redmine ProxyPassReverse /redmine http://127.0.0.1:3000/redmine
- in Redmine
config/additional_environment.rb
config.relative_url_root = '/redmine'
- started thin with --prefix /redmine
I don't use Redmine::Utils::relative_url_root
because I don't want to modify a versionned file, and Redmine::Utils isn't available in the additional_environment.rb context. Without the config.relative_url_root
, the only problem I had was the
missing '/redmine' for assets.
I use ruby 1.9.3 and thin 1.5 on windows.
Regards
Updated by Etienne Massip about 12 years ago
Alex Muntada wrote:
I understand the need to serve assets from a web server but that shouldn't mean that they can't be served by Rack under
/redmine
the same way they are being served under/
by default.
The fact is that they shouldn't be served under /
neither because Rails production default is to disable ActionDispatch::Static
middleware; Redmine just hasn't follow this way for now.
If you really want that Rack server to publish your static file then you have to remove the default_scope
declaration, keep the config.asset_path
and edit your config.ru
this way:
# This file is used by Rack-based servers to start the application.
require ::File.expand_path('../config/environment', __FILE__)
map '/redmine' do
run RedmineApp::Application
end
AFAICR.
Is there any recommended and setup for Redmine outside
/
? Passenger maybe?
All are good solutions: FCGI, Passenger, a Rack server, even TorqueBox|Trinidad|Tomcat+Warbler on JRuby. But if you are using a Rack server, then the right solution is the one described by Teddy.
Edit: except I would replace config.relative_url_root = '/redmine'
with config.asset_path = '/redmine%s'
.
Updated by Teddy L about 12 years ago
Etienne Massip wrote:
Edit: except I would replace
config.relative_url_root = '/redmine'
withconfig.asset_path = '/redmine%s'
.
Just tried this, and it still works perfectly for me. But asset_path works because assets pipeline is currently disabled in redmine. I don't know how assets pipeline works, but wouldn't be more reliable in time to use relative_url_root ?
Regards
Updated by Alex Muntada about 12 years ago
Teddy L wrote:
- started thin with --prefix /redmine
Okay, i was starting the Rack server the wrong way:
script/rails server thin -e production -b localhost -p 3000
Instead of:
bundle exec thin -e production -a localhost -p 3000 --prefix /redmine start
After cleaning up repo changes and creating the additional_environment.rb
file as you pointed out, running thin through bundle worked wonders :)
Thanks a lot!
Updated by Alex Muntada about 12 years ago
Etienne Massip wrote:
[...] But if you are using a Rack server, then the right solution is the one described by Teddy.
Edit: except I would replace
config.relative_url_root = '/redmine'
withconfig.asset_path = '/redmine%s'
.
Works for me too, thanks!
Updated by Etienne Massip about 12 years ago
Teddy L wrote:
Etienne Massip wrote:
Edit: except I would replace
config.relative_url_root = '/redmine'
withconfig.asset_path = '/redmine%s'
.Just tried this, and it still works perfectly for me. But asset_path works because assets pipeline is currently disabled in redmine. I don't know how assets pipeline works, but wouldn't be more reliable in time to use relative_url_root ?
Hard to tell, Rails crew has not clear statement about handling of sub-URI but you might be right as "edge guides does not include asset_path
anymore and relative_url_root
is still here.
I will use asset_path
for now because it doesn't make sense to use a parameter named relative_url_root
which only affects assets URLs, but it's a personnal choice.
Updated by Teddy L about 12 years ago
Etienne Massip wrote:
Hard to tell, Rails crew has not clear statement about handling of sub-URI but you might be right as "edge guides does not include
asset_path
anymore andrelative_url_root
is still here.I will use
asset_path
for now because it doesn't make sense to use a parametere namedrelative_url_root
which only affects assets URLs, but it's a personnal choice.
You are right, it make more sense to use asset_path for an asset path issue. I hope we won't have to add additionnal configuration to handle that in the future.
I noticed a little side effect by using asset_path: no more "?mtime" in assets urls.
Regards
Updated by Alex Muntada about 12 years ago
FWIW, i'd like to add that some extra Apache config is needed when the backend uses SSL, e.g.:
SSLProxyEngine on SSLProxyVerify require # use optional_no_ca if backend has an auto-signed cert <Proxy https://backend.example.com/redmine> RequestHeader set X_FORWARDED_PROTO 'https' Order allow,deny Allow from all </Proxy> <Location /redmine> ProxyPass https://backend.example.com/redmine ProxyPassReverse https://backend.example.com/redmine </Location>
Otherwise, any form submit will end up redirecting to the http version of the original URL.
Updated by Drew Keller about 12 years ago
The setup Teddy describes works for except I have to use config.asset_path. All of the commented out items do not work for me (most output the file missing error in apache log).
.conf
Alias /redmine "c:/path/to/redmine-2.1.2"
development.rb
#config.action_controller.relative_url_root = '/redmine' #config.relative_url_root = '/redmine' #Redmine::Utils::relative_url_root = "/redmine" #ActionController::Base.relative_url_root = "/redmine" #ActionController::AbstractRequest.relative_url_root = "/redmine" config.asset_path = '/redmine%s'
start thin with prefix /redmine
thin 1.5 on windows, redmine 2.1.2, ruby 1.9.2
Updated by Aleksandar Pavic almost 7 years ago
I've also performed this
[[
https://stackoverflow.com/questions/8522813/how-to-set-root-url]]
So I'm not sure which actually resolved it.
But I can confirm it's still problem with 3.4
Updated by MyungAun Park almost 4 years ago
This is good for me.
#11881-20
cd redmine/public ln -s . redmine