Project

General

Profile

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

Cyril Jouve, 2018-03-08 22:24

1 15 Simon Deziel
{{toc}}
2
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 16 Evgeniy Dushistov
h2. Working variant (Sun Jun 26 13:48:50 MSK 2016)
8
9
Change the following lines at the bottom of your config/environment.rb
10
11
<pre><code lang="ruby">
12
# Initialize the Rails application
13
Rails.application.initialize!
14
</code></pre>
15
16
to 
17
18
<pre><code lang="ruby">
19
RedmineApp::Application.routes.default_scope = "/redmine"
20
# Initialize the Rails application
21
Rails.application.initialize!
22
</code></pre>
23
24
25 6 Luca Pireddu
h2.  Using Redmine::Utils (preferred solution)
26
27
Add the following line at the bottom of your config/environment.rb
28
29
<pre>
30
Redmine::Utils::relative_url_root = "/redmine"
31
</pre>
32
33
Then restart your application.
34
35
h2. Using Rails features
36 1 Jean-Baptiste Barth
37
Add the following line at the end of your config/environment.rb :
38
<pre>
39
ActionController::AbstractRequest.relative_url_root = "/redmine"
40 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
41
<pre>
42
ActionController::Base.relative_url_root = "/redmine"
43 5 Michael Vance
</pre>for the class name.
44 1 Jean-Baptiste Barth
45
h2. Using Mongrel features
46
47 2 Jean-Baptiste Barth
If you run Redmine under Mongrel server, you can alternatively use the "--prefix" option of Mongrel :
48 1 Jean-Baptiste Barth
<pre>
49 2 Jean-Baptiste Barth
mongrel_rails start --prefix=/redmine
50 7 Tiemo Vorschuetz
</pre>
51
_*Mongrel_rails service "--prefix" directive does NOT work with Rails 2.3.x*
52
To fix this issue create a file config/initializers/patch_for_mongrel.rb [name of file can be anything]:_
53
<pre>
54
# Fix for mongrel which still doesn't know about Rails 2.2's changes, 
55
# We provide a backwards compatible wrapper around the new
56
# ActionController::base.relative_url_root,
57
# so it can still be called off of the actually non-existing
58
# AbstractRequest class.
59
60
module ActionController
61
  class AbstractRequest < ActionController::Request
62
    def self.relative_url_root=(path)
63
      ActionController::Base.relative_url_root=(path)
64
    end
65
    def self.relative_url_root
66
      ActionController::Base.relative_url_root
67
    end
68
  end
69
end
70
#
71
# Thanks to http://www.ruby-forum.com/topic/190287
72
</pre>
73
74
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) :
75 1 Jean-Baptiste Barth
<pre>
76
ProxyPass /redmine http://localhost:8000/redmine
77
ProxyPassReverse /redmine http://localhost:8000/redmine
78
</pre>
79
80
h2. Using Passenger (aka mod_rails) features
81
82 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.
83 1 Jean-Baptiste Barth
84 12 shaun williams
h2. Using Passenger+Nginx features
85
86
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)
87
88 13 Yehuda Katz
h2. Using Unicorn+Nginx
89
90
nginx config:
91
<pre>
92
location /redmine {
93
        alias   <PATH_TO>/redmine/public;
94
95
        try_files $uri/index.html $uri.html $uri @app;
96
     }
97
</pre>
98
99
config/routes.rb
100
<pre>
101
102
Redmine::Utils::relative_url_root = "/redmine"
103
104
RedmineApp::Application.routes.draw do
105 14 Yehuda Katz
scope Redmine::Utils::relative_url_root do
106 13 Yehuda Katz
  root :to => 'welcome#index', :as => 'home'
107
.....
108
end
109
end
110
</pre>
111
112 1 Jean-Baptiste Barth
h2. With a reverse proxy
113
114
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 :
115
<pre>
116
ProxyPass /redmine http://real-redmine-server.localdomain:3000/
117
ProxyPassReverse /redmine http://real-redmine-server.localdomain:3000/
118 2 Jean-Baptiste Barth
</pre>See Apache official documentation to adapt it.
119 1 Jean-Baptiste Barth
120 17 Cyril Jouve
h2. With puma
121
122
# Define "RAILS_RELATIVE_URL_ROOT environment variable":http://guides.rubyonrails.org/configuring.html#deploy-to-a-subdirectory-relative-url-root :
123
<pre><code class="bash>
124
export RAILS_RELATIVE_URL_ROOT=/redmine
125
</code></pre> or use [[HowTo_Install_Redmine_in_a_sub-URI#Using-RedmineUtils-preferred-solution|RedmineUtils method]]
126
This allows rails to generate urls prefixed by RAILS_RELATIVE_URL_ROOT.
127
# Then update you config.ru:
128
<pre><code class="ruby">
129
# This file is used by Rack-based servers to start the application.
130
131
require ::File.expand_path('../config/environment',  __FILE__)
132
map ENV['RAILS_RELATIVE_URL_ROOT'] || '/' do
133
  run RedmineApp::Application
134
end
135
</code></pre> This allows rack to handle urls prefixed with RAILS_RELATIVE_URL_ROOT.
136
137
Both points are necessary.
138 1 Jean-Baptiste Barth
139 2 Jean-Baptiste Barth
h2. Old versions of Redmine and Rails
140 1 Jean-Baptiste Barth
141 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.
142
143 1 Jean-Baptiste Barth
h2. References
144
145 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.
146 10 Zack s
147
Windows : Configuring Ruby On Rails App in a subdirectory under Apache - http://stackoverflow.com/a/470973/663172
148 11 Zack s
149
Configuring ruby on rails Action Controller - http://edgeguides.rubyonrails.org/configuring.html#configuring-action-controller