3
0

Delete article

Deleted articles cannot be recovered.

Draft of this article would be also deleted.

Are you sure you want to delete this article?

More than 3 years have passed since last update.

GitLab Omnibusで、GitLab PagesをワイルドカードDNSを使わずにサブディレクトリで運用する。かつ、アクセスコントロールも使えるようにする。

Last updated at Posted at 2021-07-14

やること

GitLab Omnibusで、GitLab PagesをワイルドカードDNSを使わずにサブディレクトリで運用する。かつ、アクセスコントロールも使えるようにする。

ほうしん

  • なるべくApache2の設定でなんとかする。
  • GitLab自体を改造しない。

このほうしんでできないこと

  • GitLabのGUIで表示されているGitLab Pagesへのリンクは、いずれもサブドメインのURLになっているので、クリックしてもアクセスできない。
  • gitlab_pages['artifacts_server'] = true にしても、上記と同じ理由で、アーティファクトからGitLab Pagesのお目当てのページに飛べない。
  • かなしい。

しょうち

非公式の方法なのでいつまで通用するか分からない。

よんだ

かんきょう

  • Debian 10
  • apache2 v2.4.38-3+deb10u5
  • gitlab-ee v14.0.5-ce.0
  • GitLabのFQDN: gitlab.example.net
  • GitLab PagesのFQDN: pages.example.net

GitLab GUIでのせってい

Admin Area > Applicationsでアプリケーションを追加する。以下の設定でアプリケーションを追加する。Application IDとSecretは自動生成される。Callback URLの本来の値は https://projects.pages.example.net/auth だが、サブディレクトリで運用するので以下のようにする。GitLab Pagesでアクセスコントロールを有効にするのに必要になる。Scopesはデフォルトは api だが read_api に下げても良い。

GitLabのせっていふぁいる

  • 以下の設定を追記する。gitlab_idgitlab_secretには上記で追加したアプリケーションのApplication IDとSecretを書く。
  • 以下の設定を行っていると、それぞれの設定項目に応じてGitLabのGUIにGitLab Pagesの設定メニューが現れる。
/etc/gitlab/gitlab.rb
pages_external_url 'https://pages.example.net'
gitlab_pages['enable'] = true
gitlab_pages['external_http'] = []
gitlab_pages['external_https'] = []
gitlab_pages['access_control'] = true
gitlab_pages['auth_redirect_uri'] = 'https://pages.example.net/projects/auth'
gitlab_pages['gitlab_id'] = '???'
gitlab_pages['gitlab_secret'] = '???'
gitlab_pages['auth_scope'] = 'read_api'

以下のコマンドで設定を反映させる。

$ sudo gitlab-ctl reconfigure

Apache2のせってい

  • つらい。
<VirtualHost *:80 *:443>
  ServerName pages.example.net
  # Let's Encryptの設定
  SSLEngine on
  Include               /etc/letsencrypt/options-ssl-apache.conf
  SSLCertificateFile    /etc/letsencrypt/live/pages.example.net/fullchain.pem
  SSLCertificateKeyFile /etc/letsencrypt/live/pages.example.net/privkey.pem
  # OAuth2関連の書き換え
  RewriteEngine On
  RewriteCond %{QUERY_STRING} (.*domain=http:\/\/)(?:[^.]*\.)(.*)$
  RewriteRule ".*" http://127.0.0.1:8090/auth?%1%2 [P,S]
  RewriteCond %{QUERY_STRING} (.*code=.*)$
  RewriteRule ".*" http://127.0.0.1:8090/auth?%1 [P,S]
  # リダイレクト先の書き換え
  Header edit Location http://(.*).(pages.example.net)/(.?) https://$2/$1/$3
  # リクエストの書き換え  
  RewriteCond %{REQUEST_URI} ^/(.*?)/(.*)/?
  RewriteRule ".*" "http://127.0.0.1:8090/%2/" [P,QSA,E=PAGESUSER:%1]
  RewriteCond %{REQUEST_URI} !^/(.*?)/(.*)/?
  RewriteRule ".*" "http://127.0.0.1:8090/" [P,QSA]
  <If "-T reqenv('PAGESUSER')">
    # eを忘れずに
    RequestHeader set Host "%{PAGESUSER}e.pages.example.net"
  </If>
</VirtualHost>

Apache2のさいきどう

$ sudo systemctl restart apache2

きぼう

  • サブディレクトリ運用公式対応してほしい。
3
0
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
3
0

Delete article

Deleted articles cannot be recovered.

Draft of this article would be also deleted.

Are you sure you want to delete this article?