HowTo Install Redmine in a sub-URI » History » Version 15

Simon Deziel, 2016-03-13 21:36

1 15 Simon Deziel
{{toc}}
2 15 Simon Deziel
3 3 Jean-Philippe Lang
h1. HowTo Install Redmine in a sub-URI
4 1 Jean-Baptiste Barth
5 2 Jean-Baptiste Barth
This page explains how to run Redmine in a subdirectory of your site, for instance @http://www.mysite.com/redmine/@ ; in such a case, you can feel lost because the classic Redmine install does not work directly, and the links to css or javascript files seem to be broken. In this page, we assume you want to run Redmine under "/redmine/" subdirectory of your site.
6 1 Jean-Baptiste Barth
7 6 Luca Pireddu
h2.  Using Redmine::Utils (preferred solution)
8 6 Luca Pireddu
9 6 Luca Pireddu
Add the following line at the bottom of your config/environment.rb
10 6 Luca Pireddu
11 6 Luca Pireddu
<pre>
12 6 Luca Pireddu
Redmine::Utils::relative_url_root = "/redmine"
13 6 Luca Pireddu
</pre>
14 6 Luca Pireddu
15 6 Luca Pireddu
Then restart your application.
16 6 Luca Pireddu
17 6 Luca Pireddu
h2. Using Rails features
18 1 Jean-Baptiste Barth
19 1 Jean-Baptiste Barth
Add the following line at the end of your config/environment.rb :
20 1 Jean-Baptiste Barth
<pre>
21 1 Jean-Baptiste Barth
ActionController::AbstractRequest.relative_url_root = "/redmine"
22 4 Michael Vance
</pre>Rails will then prefix all links with "/redmine". It can be considered as the simplest, cleanest and most flexible solution. Then restart your application. In more recent versions of Rails the class hierarchy has changed slightly and you will need to use
23 4 Michael Vance
<pre>
24 4 Michael Vance
ActionController::Base.relative_url_root = "/redmine"
25 5 Michael Vance
</pre>for the class name.
26 1 Jean-Baptiste Barth
27 1 Jean-Baptiste Barth
h2. Using Mongrel features
28 1 Jean-Baptiste Barth
29 2 Jean-Baptiste Barth
If you run Redmine under Mongrel server, you can alternatively use the "--prefix" option of Mongrel :
30 1 Jean-Baptiste Barth
<pre>
31 2 Jean-Baptiste Barth
mongrel_rails start --prefix=/redmine
32 7 Tiemo Vorschuetz
</pre>
33 7 Tiemo Vorschuetz
_*Mongrel_rails service "--prefix" directive does NOT work with Rails 2.3.x*
34 7 Tiemo Vorschuetz
To fix this issue create a file config/initializers/patch_for_mongrel.rb [name of file can be anything]:_
35 7 Tiemo Vorschuetz
<pre>
36 7 Tiemo Vorschuetz
# Fix for mongrel which still doesn't know about Rails 2.2's changes, 
37 7 Tiemo Vorschuetz
# We provide a backwards compatible wrapper around the new
38 7 Tiemo Vorschuetz
# ActionController::base.relative_url_root,
39 7 Tiemo Vorschuetz
# so it can still be called off of the actually non-existing
40 7 Tiemo Vorschuetz
# AbstractRequest class.
41 7 Tiemo Vorschuetz
42 7 Tiemo Vorschuetz
module ActionController
43 7 Tiemo Vorschuetz
  class AbstractRequest < ActionController::Request
44 7 Tiemo Vorschuetz
    def self.relative_url_root=(path)
45 7 Tiemo Vorschuetz
      ActionController::Base.relative_url_root=(path)
46 7 Tiemo Vorschuetz
    end
47 7 Tiemo Vorschuetz
    def self.relative_url_root
48 7 Tiemo Vorschuetz
      ActionController::Base.relative_url_root
49 7 Tiemo Vorschuetz
    end
50 7 Tiemo Vorschuetz
  end
51 7 Tiemo Vorschuetz
end
52 7 Tiemo Vorschuetz
#
53 7 Tiemo Vorschuetz
# Thanks to http://www.ruby-forum.com/topic/190287
54 7 Tiemo Vorschuetz
</pre>
55 7 Tiemo Vorschuetz
56 7 Tiemo Vorschuetz
You may not run Mongrel on port 80 : if you have an Apache server on the same host, and you run Mongrel on port 8000, you can use the following Apache config to redirect (with Apache's mod_proxy enabled) :
57 1 Jean-Baptiste Barth
<pre>
58 1 Jean-Baptiste Barth
ProxyPass /redmine http://localhost:8000/redmine
59 1 Jean-Baptiste Barth
ProxyPassReverse /redmine http://localhost:8000/redmine
60 1 Jean-Baptiste Barth
</pre>
61 1 Jean-Baptiste Barth
62 1 Jean-Baptiste Barth
h2. Using Passenger (aka mod_rails) features
63 1 Jean-Baptiste Barth
64 9 Zack s
If you run Redmine under Apache web server with Phusion Passenger module, you can follow "this guide":http://www.modrails.com/documentation/Users%20guide%20Apache.html#deploying_rails_to_sub_uri ; please note it won't work correctly on some versions of Passenger or some Linux distributions.
65 1 Jean-Baptiste Barth
66 12 shaun williams
h2. Using Passenger+Nginx features
67 12 shaun williams
68 12 shaun williams
See "official guide":http://modrails.com/documentation/Users%20guide%20Nginx.html#deploying_rails_to_sub_uri (This is the only solution that worked for me - 30 Oct 2012)
69 12 shaun williams
70 13 Yehuda Katz
h2. Using Unicorn+Nginx
71 13 Yehuda Katz
72 13 Yehuda Katz
nginx config:
73 13 Yehuda Katz
<pre>
74 13 Yehuda Katz
location /redmine {
75 13 Yehuda Katz
        alias   <PATH_TO>/redmine/public;
76 13 Yehuda Katz
77 13 Yehuda Katz
        try_files $uri/index.html $uri.html $uri @app;
78 13 Yehuda Katz
     }
79 13 Yehuda Katz
</pre>
80 13 Yehuda Katz
81 13 Yehuda Katz
config/routes.rb
82 13 Yehuda Katz
<pre>
83 13 Yehuda Katz
84 13 Yehuda Katz
Redmine::Utils::relative_url_root = "/redmine"
85 13 Yehuda Katz
86 13 Yehuda Katz
RedmineApp::Application.routes.draw do
87 14 Yehuda Katz
scope Redmine::Utils::relative_url_root do
88 13 Yehuda Katz
  root :to => 'welcome#index', :as => 'home'
89 13 Yehuda Katz
.....
90 13 Yehuda Katz
end
91 13 Yehuda Katz
end
92 13 Yehuda Katz
</pre>
93 13 Yehuda Katz
94 1 Jean-Baptiste Barth
h2. With a reverse proxy
95 1 Jean-Baptiste Barth
96 1 Jean-Baptiste Barth
If you have an Apache webserver in front of it (with mod_proxy enabled), or an Apache reverse proxy on another machine, you can run Redmine on a specific port and use this kind of config so it appears to be running in a subdirectory :
97 1 Jean-Baptiste Barth
<pre>
98 1 Jean-Baptiste Barth
ProxyPass /redmine http://real-redmine-server.localdomain:3000/
99 1 Jean-Baptiste Barth
ProxyPassReverse /redmine http://real-redmine-server.localdomain:3000/
100 2 Jean-Baptiste Barth
</pre>See Apache official documentation to adapt it.
101 1 Jean-Baptiste Barth
102 1 Jean-Baptiste Barth
103 2 Jean-Baptiste Barth
h2. Old versions of Redmine and Rails
104 1 Jean-Baptiste Barth
105 2 Jean-Baptiste Barth
If you run a very old version of Redmine (don't know exactly which ones), maybe your version of Rails' ActionController does not support the "relative_url_root" mentionned above. Then you can look at "this page":https://www.riscosopen.org/wiki/documentation/pages/Running+Rails+applications+from+subdirectories/versions/16 to reproduce the same behaviour, but it is NOT a very good idea in most cases, you should consider upgrading Redmine.
106 2 Jean-Baptiste Barth
107 1 Jean-Baptiste Barth
h2. References
108 1 Jean-Baptiste Barth
109 8 Zack s
If this page did not answered your problems, you can see #2508 or "this thread":http://www.redmine.org/boards/2/topics/2244.
110 10 Zack s
111 10 Zack s
Windows : Configuring Ruby On Rails App in a subdirectory under Apache - http://stackoverflow.com/a/470973/663172
112 11 Zack s
113 11 Zack s
Configuring ruby on rails Action Controller - http://edgeguides.rubyonrails.org/configuring.html#configuring-action-controller