Gitlabをサブディレクトリでアクセスできるようにする方法をメモ

[CentOS]Gitlabを公式ドキュメントに従いインストールする(およそ3分作業)
上記よりGitlabのインストールが終わったので、それをサブディレクトリ「http://[ipアドレス/ホスト名]:8000/gitlab」でアクセスできるようにする
vagrant,vpsなどにインストールされているcentosでも同作業。

手順の確認

application.rb(全体設定)に手順が記載されている。

まず中身の確認

cat /opt/gitlab/embedded/service/gitlab-rails/config/application.rb

結果: ※ 上部に記載されている

    # Note that following settings need to be changed for this to work.
    # 1) In your application.rb file: config.relative_url_root = "/gitlab"
    # 2) In your gitlab.yml file: relative_url_root: /gitlab
    # 3) In your unicorn.rb: ENV['RAILS_RELATIVE_URL_ROOT'] = "/gitlab"
    # 4) In ../gitlab-shell/config.yml: gitlab_url: "http://127.0.0.1/gitlab"
    # 5) In lib/support/nginx/gitlab : do not use asset gzipping, remove block starting with "location ~ ^/(assets)/"

※5)はやらなくてよい

1.gitlabの設定情報を反映させる

設定内容を反映させる

gitlab-ctl reconfigure

このコマンドを実行すると設定ファイルの上書きが行われる。そのためこれ移行したの手順でファイルを編集したあとに「reconfigure」を実行すると内容が消えてしまうファイルがあるため、再度行わない事。

2.application.rbファイルの編集

「1) In your application.rb file: config.relative_url_root = “/gitlab”」の実行

application.rb(全体設定)の設定ファイルを開く

vim /opt/gitlab/embedded/service/gitlab-rails/config/application.rb

config.relative_url_rootをコメントアウト(#)を消して有効にする

config.relative_url_root = "/gitlab"

※手元環境だと65行目

3.gitlab.ymlファイルの編集

「2) In your gitlab.yml file: relative_url_root: /gitlab」の実行

gitlabの設定ファイルを開く

vim /var/opt/gitlab/gitlab-rails/etc/gitlab.yml

relative_url_rootをコメントアウト(#)を消して有効にする

relative_url_root: /gitlab

※手元環境だと24行目

4.unicon.rbファイルの編集

「3) In your unicorn.rb: ENV['RAILS_RELATIVE_URL_ROOT'] = “/gitlab”」の実行
uniconはrailsを動作させるためのサーバになり、gitlabはuniconで動作している

uniconの設定ファイルを開く

vim /var/opt/gitlab/gitlab-rails/etc/unicorn.rb

下記コードの何れかに追記(何処でも良いと思われるが一番上部に設置)

ENV['RAILS_RELATIVE_URL_ROOT'] = "/gitlab"

5.config.ymlファイルの編集

「4) In ../gitlab-shell/config.yml: gitlab_url: “http://127.0.0.1/gitlab”」の実行

configファイルを開く

vim /var/opt/gitlab/gitlab-shell/config.yml

gitlab_urlへサブディレクトリのgitlabを追加する

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

※手元環境だと9行目

6.設定ファイルの反映

gitlab-ctl restart

6.ブラウザアクセス

http://[ipアドレス/ホスト名]:8000/gitlab

でアクセス出来ればOK

その他おすすめの備忘録

Tagged with:
 

コメントを残す