From 11df244dc53ddcb36c5433198c6b546188586a24 Mon Sep 17 00:00:00 2001 From: xdavidwu Date: Thu, 27 Sep 2018 12:47:22 +0000 Subject: [PATCH] posts: add gitlab-pages-without-domain --- .../2018-09-27-gitlab-pages-without-domain.md | 38 +++++++++++++++++++ 1 file changed, 38 insertions(+) create mode 100644 _posts/2018-09-27-gitlab-pages-without-domain.md diff --git a/_posts/2018-09-27-gitlab-pages-without-domain.md b/_posts/2018-09-27-gitlab-pages-without-domain.md new file mode 100644 index 0000000..cac6c0c --- /dev/null +++ b/_posts/2018-09-27-gitlab-pages-without-domain.md @@ -0,0 +1,38 @@ +--- +title: "在不需要 domain 的情況下使用 GitLab Pages" +categories: + - nginx +tags: + - nginx + - gitlab +--- + +在我的 case 中 GitLab 外面正好有一層 nginx 的 reverse proxy 可以利用 + +想法: + +``` +傳來 /pages//... 的 request +reverse proxy 內部將 uri 的 /pages/ 刪除 +加上 Hosts: .gitlab.domain 的 header +傳到 GitLab 取得原本該在 .gitlab.domain/... 的網頁 +``` + +實作 nginx config: + +``` +location ~ /pages/(?[^/]+)/ { + rewrite ^/pages/([^/]+)/(.*) /$2 break; + proxy_pass http://; + proxy_set_header Host $user.gitlab.domain; + proxy_redirect //$user.gitlab.domain/ https://gitlab.domain/pages/$user/; +} +``` + +最後的 `proxy_redirect` 後面的 url 改一下就能達到連 GitLab 本身都不需要 domain + +缺 domain, wildcard domain, wildcard tls 中任一項都能這樣硬上 GitLab Pages + +不過美中不足的是 GitLab 設定裡的連結還是 .gitlab.domain 的格式 + +要直接放在 /pages/ 而非 /pages// 的 repo 還是得命名成 .gitlab.domain \ No newline at end of file -- 2.43.0