Redmine not working properly from a subdirectory

Added by Jeroen van den Broek over 7 years ago

First of all, I'm running Redmine from a Synology NAS which is running a really lightweight Linux distro, so most easy solutions you might be able to come up with (using Mongrel or Passenger) are not as easy as you'd think. For now I'm using WEBrick and considering the fact only 7 people will be using it, that should do fine.

Right, with that out of the way, I'm trying to get Redmine to run from http://host/redmine. For this I'm setting up a reverse proxy from Apache to WEBrick. I'm aware of http://www.redmine.org/projects/redmine/wiki/HowTo_Install_Redmine_in_a_sub-URI but this is not working out for me. My current setup:

At the end of config/environment.rb:

ActionController::Base.relative_url_root = "/redmine" 

I've tried the Redmine::Utils variant as well, but that produces the same problem.

In my httpd.conf:

LoadModule proxy_module modules/mod_proxy.so
LoadModule proxy_http_module  modules/mod_proxy_http.so
ProxyRequests Off
ProxyPreserveHost On
ProxyPass /redmine/ http://127.0.0.1:3000/
ProxyPassReverse /redmine/ http://127.0.0.1:3000/

And finally, an .htaccess file in Apache's document root:

RewriteEngine On
RewriteBase /
RewriteCond %{REQUEST_FILENAME} !-f
RewriteCond %{REQUEST_FILENAME} !-d
RewriteRule (.*) /redmine/$1 [L]

RedirectMatch ^/redmine$ /redmine/
RedirectMatch ^/$ /redmine/

As you can probably guess from the RewriteRules: Redmine is actually running on http://host/redmine but the internal links are all pointing to / instead of to /redmine. Strangely enough, the assets get linked correctly though. From the HTML source code:
<script src="/redmine/javascripts/prototype.js?1338917025" type="text/javascript"></script>
...but also:
<a href="/logout" class="logout">Sign out</a>

Relevant version info:

Environment:
  Redmine version                          2.0.2.stable
  Ruby version                             1.9.3 (x86_64-linux)
  Rails version                            3.2.5
  Environment                              production
  Database adapter                         Mysql2
Redmine plugins:
  no plugin installed

While the current setup works in a way, it's not a desirable situation for me. I would prefer to ditch the rewriterules and have internal Redmine links point to the correct subdirectory. Another possible solution would be setting up a vhost, but for some reason whenever I try that, all URLs just get automatically redirected to Synology's DSM interface. This is probably Synology's own Apache settings interfering with mine.

Replies (9)

RE: Redmine not working properly from a subdirectory - Added by Ivan Wu over 7 years ago

Same here, in short, when I used


ActionController::Base.relative_url_root = "/redmine"

For redmine 1.4.x , accessing http://host:port/redmine shows page without css & js (directed to /redmine),
however, when it comes to redmine 2.x , accessing the same address shows "page not found".

Consequently, it requires url rewrite to complete the sub-uri setup, which is not expected.

RE: Redmine not working properly from a subdirectory - Added by Jeroen van den Broek over 7 years ago

Ivan Wu wrote:

For redmine 1.4.x , accessing http://host:port/redmine shows page without css & js (directed to /redmine),

I get exactly the opposite. It includes all the CSS & JS but links simply do not point to /redmine/ as a base but to /.

RE: Redmine not working properly from a subdirectory - Added by Jeroen van den Broek over 7 years ago

I've been fiddling with it for over a week and a half now with no success whatsoever. Is there no one who can shed some light on this matter?

RE: Redmine not working properly from a subdirectory - Added by Ivan Wu over 7 years ago

As far as I know, following the instructions from HowTo_Install_Redmine_in_a_sub-URI should change all the links to sub directory indicated.

I've tested it on ver. 1.4.4 by adding following config in environment.rb . Make sure you do the same and restart the server.

ActionController::Base.relative_url_root = "/redmine" 

Here's my Nginx server configuration for your reference. I created a symbolic link from sub directory "/mgt" to "/redmine/public" to accelerate the process by letting Nginx deal with static resource loading while forwarding the rest to Thin ruby container.

upstream thinCluster
{
server 127.0.0.1:9000;
server 127.0.0.1:9001;
} 

server
    {
        listen       80;
        server_name 113.10.237.16;
        index index.html index.htm index.php;
        root /home/wwwroot;

location  ^~ /mgt{
try_files $uri @thinProxy;
}

location @thinProxy{
proxy_redirect off;
proxy_set_header Host $http_host;
proxy_set_header X-Real-IP $remote_addr;
proxy_set_header X-Forwarded-For $proxy_add_x_forwarded_for;
proxy_pass http://thinCluster;
}
...

Note that this won't work under 2.0.x stated previously.

RE: Redmine not working properly from a subdirectory - Added by Jeroen van den Broek over 7 years ago

I am aware of both that setting and that wiki page. I've even linked them in my first post. They are what results into my problem, which is a partially working situation where all content is sent from the correct paths but where links simply point to the wrong place.

Thanks for pointing out your Nginx configuration, but seeing as I use both 2.0.2 and WEBrick I'm afraid I can't really apply it.

RE: Redmine not working properly from a subdirectory - Added by Sean Davis over 7 years ago

Tested on 2.0.3. I get the same problem. Adding

ActionController::Base.relative_url_root = "/redmine" 

gets js and css links correct, but all other links are incorrect. I see a couple of notes above that this might or might not work in 2.0.x, so any ideas on where to go are appreciated. I am proxying behind nginx.

RE: Redmine not working properly from a subdirectory - Added by Etienne Massip over 7 years ago

Seems to be a 2.x bug indeed (already reported).

Have a look at RE: Redmine 2.0 "No route matches" which seems to be a working solution.

RE: Redmine not working properly from a subdirectory - Added by Sean Davis over 7 years ago

Yes, that is the bug--thanks. I tried the solution in your link and still end up with either the js/css working or the dynamic pages, but never both.

RE: Redmine not working properly from a subdirectory - Added by Jeroen van den Broek over 7 years ago

Same here. After applying the fix I get the situation that the javascripts and CSS are not available through /redmine anymore while the other links now are working. The links correctly go to /redmine/javascripts/application.js?1338917025 (for instance), but the file is only accessible through /javascripts/application.js?1338917025.

(1-9/9)