LoginSignup
6
7

More than 5 years have passed since last update.

GitLabをサブディレクトリで運用する(omnibus 7.8.1) ※2016/04/05 追記あり

Last updated at Posted at 2015-03-18

追記(2016/04/05)

GitLab 8.5 にて、experimentalではありますが、標準でサブディレクトリ運用できるような機能追加がされました。
以下のURIに実装方法が書いてあるので、基本的にはこちらをご利用ください。

当時の参考資料として、以下の記事は残しておきますが、古い資料であることをご了承ください。

ここから元記事

ほぼ下の記事通りなのですが、このままだとunicornがエラーを吐き続けて502 GitLab is not respondingを吐くので、改めて纏めておきます。

GitLab omnibus をサブディレクトリで運用する

作業環境

作業

行数はあくまで参考です。

  • /opt/gitlab/embedded/cookbooks/gitlab/templates/default/gitlab.yml.erb の24行目
    # relative_url_root: /gitlab

     relative_url_root: /gitlab

に変更

  • /opt/gitlab/embedded/cookbooks/gitlab/templates/default/unicorn.rb.erb ファイルの一番最後の行に以下を追加
ENV['RAILS_RELATIVE_URL_ROOT'] = '/gitlab'

上記記事ではダブルクォート(")ですが、現在の環境ではシングルクォート(')でないとunicornがエラーを出力するので気をつけます。

  • /opt/gitlab/embedded/cookbooks/gitlab/templates/default/gitlab-shell-config.yml.erb の9行目
gitlab_url: "<%= @api_url %>"

gitlab_url: "http://127.0.0.1:8080/gitlab"

に変更

unicornが動作するURLを指定します。デフォルトだと127.0.0.1:8080で動作するので、サブディレクトリの場合はそのように修正してください。

  • /opt/gitlab/embedded/cookbooks/gitlab/templates/default/nginx-gitlab-http.conf.erb の84行目
  location / {
    ## Serve static files from defined root folder.
    ## @gitlab is a named location for the upstream fallback, see below.
    try_files $uri $uri/index.html $uri.html @gitlab;
  }

  location /gitlab {
    ## Serve static files from defined root folder.
    ## @gitlab is a named location for the upstream fallback, see below.
    alias /opt/gitlab/embedded/service/gitlab-rails/public;
    try_files $uri $uri/index.html $uri.html @gitlab;
  }

に変更

結果

この状態で sudo gitlab-ctl reconfigure することで、 http://example.com/gitlab にてGitLabを運用出来ます。
もし何らかの仕様変更があったとしても、テンプレートを編集しているのでreconfigureしても問題ないです。

おまけ

GitLabは最初のreconfigure後に初期化処理を挟んでいるようなのですが、マシンスペックによってはこれにかなり時間がかかります。
別に時間がかかっても真面に動くなら良いのですが、unicornがタイムアウトを出力してしまいタイムアウトになり続ける可能性があるので、タイムアウトと判定される時間を修正しておく事をお勧めします。

  • /etc/gitlab/gitlab.rb の223行目
# unicorn['worker_timeout'] = 60

unicorn['worker_timeout'] = 180

に変更

もしコメントアウトするような記載が無い場合は追記するだけで構いません。
180秒というのは自分の体験からなので、適宜修正してください。

6
7
0

Register as a new user and use Qiita more conveniently

  1. You get articles that match your needs
  2. You can efficiently read back useful information
  3. You can use dark theme
What you can do with signing up
6
7