Gitlab + Nginx + SSL + サブディレクトリ
で動かしたかったので設定した。結果。です。
https://example.com/gitlab みたいに。
GitlabをインストールするとNginxも一緒についてくるみたいですが,もともとサーバにはNginx入れててSSL対応もしていたので,それは使わずに。
いろいろ探ってたけど,公式のドキュメント見たらかなり楽にできました。
環境
- さくらのVPS (2Gプラン)
- Scientific Linux 7
- Nginx 1.12
- Gitlab 10.1.1
既にNginx+SSLでwebページ運用中の前提で書きます。
GitLabインストール
こちらを参考に。1番の部分はすでに入っていたので2番からやりました。
Installation methods for GitLab | GitLab
curl https://packages.gitlab.com/install/repositories/gitlab/gitlab-ee/script.rpm.sh | sudo bash sudo yum install -y gitlab-ce
設定
こちらを参考に。「Using a non-bundled web-server」の部分です。
NGINX settings - GitLab Documentation
Nginxユーザにgitlabのグループを与えてやって,Nginxから飛ばすようにすればよいらしい。(雑)
sudo usermod -G gitlab-www nginx sudo vi /etc/gitlab/gitlab.rb
Gitlabのアドレス指定を書き換える。
external_url 'https://example.com/gitlab'
以下の部分を書き換えてバンドルのNginxを殺し,既存のNginxからアクセスを受け付けるようにする。
nginx['enable'] = false web_server['external_users'] = ['nginx']
ページ中の3, 4番は同じサーバ内で動かす場合は不要っぽい。
nginx.conf設定
こちらを参考に。
web-server/nginx · master · GitLab.org / GitLab recipes · GitLab
もともとHSTS有効にしていたので,一番下のgitlab-omnibus-ssl-nginx.confを使いました。
upstream gitlab-workhorse { server unix:/var/opt/gitlab/gitlab-workhorse/socket fail_timeout=0; }
Gitlab用にlocationディレクティブを追加
location /gitlab { root /opt/gitlab/embedded/service/gitlab-rails/public; proxy_http_version 1.1; client_max_body_size 0; gzip off; ## https://github.com/gitlabhq/gitlabhq/issues/694 ## Some requests take more than 30 seconds. proxy_read_timeout 300; proxy_connect_timeout 300; proxy_redirect off; proxy_set_header Host $http_host; proxy_set_header X-Real-IP $remote_addr; proxy_set_header X-Forwarded-Ssl on; proxy_set_header X-Forwarded-For $proxy_add_x_forwarded_for; proxy_set_header X-Forwarded-Proto $scheme; proxy_pass http://gitlab-workhorse; }
起動
sudo gitlab-ctl reconfigure sudo gitlab-ctl start
起動後数分は502が出るようです。
めでたしめでたし。続きは明日にして寝る。