プロジェクト

全般

プロフィール

Vote #72653

未完了

Installed Redmine in a sub-URI: Links are generated not correctly

Admin Redmine さんがほぼ2年前に追加. ほぼ2年前に更新.

ステータス:
New
優先度:
通常
担当者:
-
カテゴリ:
Project settings_43
対象バージョン:
-
開始日:
2022/05/09
期日:
進捗率:

0%

予定工数:
category_id:
43
version_id:
0
issue_org_id:
12102
author_id:
64960
assigned_to_id:
0
comments:
22
status_id:
1
tracker_id:
1
plus1:
0
affected_version:
closed_on:
affected_version_id:
43
ステータス-->[New]

説明

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):

!redmine_wrong_urls.png!

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]


journals

You should insert it before the initialize, not replace the whole file contents.

<pre><code class="ruby">
# 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"
</code></pre>

My 2 cents :
* @Redmine::Utils::relative_url_root@ should be deprecated, it only affects static assets URLs and we should promote @config.asset_path = "/redmine2%s"@ in @application.rb@ instead
* @config.serve_static_assets@ should be explicitely set to false in @environment/production.rb@ (it is for a brand new generated Rails app). This would deactivate @ActionDispatch::Static@ middleware which is meant for development mode use only and would prevent issues such as "this one":https://github.com/rails/rails/issues/5987

--------------------------------------------------------------------------------
*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_

!2012-10-16_073110.png!

_Result for root and sample inner page (called by existing direct URL)_

!2012-10-16_073318.png! !2012-10-16_073308.png!

Stack trace for calling issue 4600:

<pre>
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'
</pre>
--------------------------------------------------------------------------------
May be routes will be helpful (see attached file)
--------------------------------------------------------------------------------
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&hellip;

Any plugin?

Last question for my knowledge, did you try with the following syntax:
<pre><code class="ruby">
RedmineApp::Application.routes.default_scope = '/redmine2'
</code></pre>
It fails for shallow routes with FCGI but it should be ok with Rack servers.

--------------------------------------------------------------------------------
Oh, you're running Webrick.

In production, please don't, it is designed for development.

--------------------------------------------------------------------------------
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).
--------------------------------------------------------------------------------
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.

--------------------------------------------------------------------------------
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:
> <pre><code class="ruby">RedmineApp::Application.routes.default_scope = '/redmine2'</code></pre>

Result is the same as for one with shallow_path ("Page not found").
--------------------------------------------------------------------------------
I'm getting 404 for all assets after setting this:

<pre><code class="ruby">
# 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"
</code></pre>

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

--------------------------------------------------------------------------------
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"@ in @application.rb@ rather than @Redmine::Utils::relative_url_root@

@Dmitry: did you fix your issue?
--------------------------------------------------------------------------------
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?
--------------------------------------------------------------------------------
Working for me with the following configurations on 2.1-stable:

* in Apache
<pre>
ProxyPass /redmine http://127.0.0.1:3000/redmine
ProxyPassReverse /redmine http://127.0.0.1:3000/redmine
</pre>
* in Redmine @config/additional_environment.rb@
<pre>
config.relative_url_root = '/redmine'
</pre>
* 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
--------------------------------------------------------------------------------
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:

<pre><code class="ruby">
# 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
</code></pre>

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'@.
--------------------------------------------------------------------------------
Etienne Massip wrote:
> Edit: except I would replace @config.relative_url_root = '/redmine'@ with @config.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
--------------------------------------------------------------------------------
Teddy L wrote:

> * started thin with --prefix /redmine

Okay, i was starting the Rack server the wrong way:

<pre>
script/rails server thin -e production -b localhost -p 3000
</pre>

Instead of:

<pre>
bundle exec thin -e production -a localhost -p 3000 --prefix /redmine start
</pre>

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!
--------------------------------------------------------------------------------
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'@ with @config.asset_path = '/redmine%s'@.

Works for me too, thanks!

--------------------------------------------------------------------------------
Teddy L wrote:
> Etienne Massip wrote:
> > Edit: except I would replace @config.relative_url_root = '/redmine'@ with @config.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":http://edgeguides.rubyonrails.org/configuring.html 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.

--------------------------------------------------------------------------------
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":http://edgeguides.rubyonrails.org/configuring.html 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 parametere named @relative_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

--------------------------------------------------------------------------------
FWIW, i'd like to add that some extra Apache config is needed when the backend uses SSL, e.g.:

<pre>
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>
</pre>

Otherwise, any form submit will end up redirecting to the http version of the original URL.
--------------------------------------------------------------------------------
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
<pre>
Alias /redmine "c:/path/to/redmine-2.1.2"
</pre>

development.rb
<pre>
#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'
</pre>

start thin with prefix /redmine

thin 1.5 on windows, redmine 2.1.2, ruby 1.9.2
--------------------------------------------------------------------------------
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
--------------------------------------------------------------------------------
This is good for me.
#11881-20

<pre>
cd redmine/public
ln -s . redmine
</pre>
--------------------------------------------------------------------------------


related_issues

relates,Confirmed,11881,FCGI mode does not support sub-URI
relates,Closed,12420,URLs in notification emails do not include the sub-URI
relates,Closed,13077,redirect to wrong back_url behind Apache reverse proxy

Admin Redmine さんがほぼ2年前に更新

  • カテゴリProject settings_43 にセット

他の形式にエクスポート: Atom PDF

いいね!0
いいね!0