- Table of contents
- HowTo Install Redmine in a sub-URI
- Working variant (Sun Jun 26 13:48:50 MSK 2016)
- Using Redmine::Utils (preferred solution)
- Using Rails features
- Using Mongrel features
- Using Passenger (aka mod_rails) features
- Using Passenger+Nginx features
- Using Unicorn+Nginx
- With a reverse proxy
- With puma
- If using Docker official image, passenger variant
- Old versions of Redmine and Rails
- References
HowTo Install Redmine in a sub-URI¶
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.
Working variant (Sun Jun 26 13:48:50 MSK 2016)¶
Change the following lines at the bottom of your config/environment.rb
# Initialize the Rails application
Rails.application.initialize!
to
RedmineApp::Application.routes.default_scope = "/redmine"
# Initialize the Rails application
Rails.application.initialize!
Using Redmine::Utils (preferred solution)¶
Add the following line at the bottom of your config/environment.rb
Redmine::Utils::relative_url_root = "/redmine"
Then restart your application.
Using Rails features¶
Add the following line at the end of your config/environment.rb :
ActionController::AbstractRequest.relative_url_root = "/redmine"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
ActionController::Base.relative_url_root = "/redmine"for the class name.
Using Mongrel features¶
If you run Redmine under Mongrel server, you can alternatively use the "--prefix" option of Mongrel :
mongrel_rails start --prefix=/redmine
Mongrel_rails service "--prefix" directive does NOT work with Rails 2.3.x
To fix this issue create a file config/initializers/patch_for_mongrel.rb [name of file can be anything]:
# Fix for mongrel which still doesn't know about Rails 2.2's changes, # We provide a backwards compatible wrapper around the new # ActionController::base.relative_url_root, # so it can still be called off of the actually non-existing # AbstractRequest class. module ActionController class AbstractRequest < ActionController::Request def self.relative_url_root=(path) ActionController::Base.relative_url_root=(path) end def self.relative_url_root ActionController::Base.relative_url_root end end end # # Thanks to http://www.ruby-forum.com/topic/190287
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) :
ProxyPass /redmine http://localhost:8000/redmine ProxyPassReverse /redmine http://localhost:8000/redmine
Using Passenger (aka mod_rails) features¶
If you run Redmine under Apache web server with Phusion Passenger module, you can follow this guide ; please note it won't work correctly on some versions of Passenger or some Linux distributions.
Using Passenger+Nginx features¶
See official guide (This is the only solution that worked for me - 30 Oct 2012)
Using Unicorn+Nginx¶
nginx config:
location /redmine { alias <PATH_TO>/redmine/public; try_files $uri/index.html $uri.html $uri @app; }
config/routes.rb
Redmine::Utils::relative_url_root = "/redmine" RedmineApp::Application.routes.draw do scope Redmine::Utils::relative_url_root do root :to => 'welcome#index', :as => 'home' ..... end end
With a reverse proxy¶
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 :
ProxyPass /redmine http://real-redmine-server.localdomain:3000/ ProxyPassReverse /redmine http://real-redmine-server.localdomain:3000/See Apache official documentation to adapt it.
With puma¶
- Define RAILS_RELATIVE_URL_ROOT environment variable :
or use RedmineUtils methodexport RAILS_RELATIVE_URL_ROOT=/redmine
This allows rails to generate urls prefixed by RAILS_RELATIVE_URL_ROOT. - Then update you config.ru:
This allows rack to handle urls prefixed with RAILS_RELATIVE_URL_ROOT.# This file is used by Rack-based servers to start the application. require ::File.expand_path('../config/environment', __FILE__) map ENV['RAILS_RELATIVE_URL_ROOT'] || '/' do run RedmineApp::Application end
Both points are necessary.
If using Docker official image, passenger variant¶
Create a Dockerfile in an empty directory with the following contents, adjusting the tag to the version you want to use:
FROM redmine:2.6.10-passenger COPY assets/passenger-nginx-config-template.erb /passenger-nginx-config-template.erb CMD ["passenger", "start", "--nginx-config-template", "/passenger-nginx-config-template.erb"]
Create a passenger-nginx-config-template.erb file in the same directory with the following contents, adjusting the sub-URI you want to use:
<%= include_passenger_internal_template('global.erb') %> worker_processes 1; events { worker_connections 4096; } http { <%= include_passenger_internal_template('http.erb', 4) %> default_type application/octet-stream; types_hash_max_size 2048; server_names_hash_bucket_size 64; client_max_body_size 1024m; access_log off; keepalive_timeout 60; underscores_in_headers on; gzip on; gzip_comp_level 3; gzip_min_length 150; gzip_proxied any; gzip_types text/plain text/css text/json text/javascript application/javascript application/x-javascript application/json application/rss+xml application/vnd.ms-fontobject application/x-font-ttf application/xml font/opentype image/svg+xml text/xml; server { server_name _; listen 0.0.0.0:3000; root '/usr/src/redmine/public'; passenger_app_env 'production'; passenger_spawn_method 'smart'; passenger_load_shell_envvars off; location ~ ^/suburi(/.*|$) { alias /usr/src/redmine/public$1; passenger_base_uri /suburi; passenger_app_root /usr/src/redmine; passenger_document_root /usr/src/redmine/public; passenger_enabled on; } } passenger_pre_start http://0.0.0.0:3000/; }
Build the Docker image and launch a container:
docker build -t redmine-in-a-sub-uri:2.6.10-passenger . docker run -d --name redmine-in-a-sub-uri -p 3000:3000 redmine-in-a-sub-uri:2.6.10-passenger
The resultant Redmine can be accessed in http://localhost:3000/suburi
Old versions of Redmine and Rails¶
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 to reproduce the same behaviour, but it is NOT a very good idea in most cases, you should consider upgrading Redmine.
References¶
If this page did not answered your problems, you can see #2508 or this thread.
Windows : Configuring Ruby On Rails App in a subdirectory under Apache - http://stackoverflow.com/a/470973/663172
Configuring ruby on rails Action Controller - http://edgeguides.rubyonrails.org/configuring.html#configuring-action-controller
Updated by David Navarro Solans over 5 years ago · 18 revisions