nginx+UnicornでRedmineを動かす 3/3 「サブディレクトリ」編
前回の「nginx+Unicornの設定」編ではURLのトップディレクトリでRedmineを動作させましたが、サブディレクトリで動作させる方法が確認できたため追加で紹介しておきます。
nginx+UnicornのサブディレクトリでRedmineを動かす
nginxの設定
nginx側では単純にlocationを変更するだけです。
$ sudo vim /etc/nginx/conf.d/default.conf
upstream unicorn-redmine {
server unix:/var/www/redmine/tmp/sockets/unicorn.sock fail_timeout=0;
}
server {
listen 80;
server_name localhost;
~中略~
location / {
root /usr/share/nginx/html;
index index.html index.htm;
}
location /redmine/ {
root /var/www/redmine/public;
index index.html index.htm;
if (-f $request_filename) { break; }
proxy_set_header X-Real-IP $remote_addr;
proxy_set_header X-Forwarded-For $proxy_add_x_forwarded_for;
proxy_set_header Host $http_host;
proxy_pass http://unicorn-redmine;
}
~中略~
}
Redmineの設定
Redmine側で設定ファイルを2つ修正します。
$ sudo vim /var/www/redmine/config/environment.rb
末尾に以下を追加
ActionController::Base.relative_url_root = "/redmine"
$ sudo vim /var/www/redmine/config.ru
以下のとおり修正
#run RedmineApp::Application
map ActionController::Base.relative_url_root || "/" do
run RedmineApp::Application
end
以上。nginxとUnicornを再起動して動作を確認します。
参考ページ
- HowTo Install Redmine in a sub-URI - Redmine
- ruby on rails - What is the replacement for ActionController::Base.relative_url_root? - Stack Overflow
おわりに
意外とあっさり解決してよかったです。これがベストな方法かどうか分かりませんが、とりあえず動作しているように見えます。
連載一覧
- nginx+UnicornでRedmineを動かす 1/3 「Redmineのインストール」編
- nginx+UnicornでRedmineを動かす 2/3 「nginx+Unicornの設定」編
- nginx+UnicornでRedmineを動かす 3/3 「サブディレクトリ」編