pages 是用來存放純 html / js /css 網頁

gitlab 是一個控管 git 庫 (放程式檔案) 的地方

gitlab 與 pages 搭配起來就是當我開發程式或檔案,上傳到 gitlab 後,它會自動佈署到 pages,就可以直接透過網頁瀏覽內容

又或是你的專案是 npm 開發內容,它會自動轉成瀏覽器可讀的 js

 

首先

環境是 ↓

gitlab 連結 : git.ssorc.tw

pages 連結: pages.ssorc.tw

gitlab 上的群組與專案:

<group>/<project>

cross/testpages

如要 clone 它就長這樣子

git clone https://git.ssorc.tw/cross/testpages/

 

而 pages 連結可以是

<group>.pages.ssorc.tw/<project>

pages.ssorc.tw/<group>/<project>

↑ 要這方式就 gitlab 要多加這條設定 (不是再一個子網站的方式)

gitlab_pages['namespace_in_path'] = true

底下設定為↑ 方式

 

# 開始設定 gitlab.rb

vi /etc/gitlab/gitlab.rb
external_url "https://git.ssorc.tw"

nginx['enable'] = true
nginx['redirect_http_to_https'] = true
nginx['ssl_certificate'] = "/etc/gitlab/ssl/server.crt"
nginx['ssl_certificate_key'] = "/etc/gitlab/ssl/server.key"


pages_external_url "https://pages.ssorc.tw"

gitlab_pages['enable'] = true
# 使用 pages.ssorc.tw 而不是 *.pages.ssorc.tw
# false 的話就要使用 cross.pages.ssorc.tw/testpages
gitlab_pages['namespace_in_path'] = true
# 如會有 pages 會找不到 git.ssorc.tw,要加這個
gitlab_pages['internal_gitlab_server'] = "http://127.0.0.1:8080"
# 如會有 ssl 驗證問題,加這個
gitlab_pages['internal_gitlab_server_cert'] = "/etc/gitlab/ssl/ca.crt"

pages_nginx['enable'] = true
pages_nginx['redirect_http_to_https'] = true
pages_nginx['ssl_certificate'] = "/etc/gitlab/ssl/server.crt"
pages_nginx['ssl_certificate_key'] = "/etc/gitlab/ssl/server.key"

 

讓 gitlab 設定套用起來

sudo gitlab-ctl reconfigure

sudo gitlab-ctl restart
# 如果 80/443 不 ok,測一下 nginx
# 單純 test nginx config 有沒有問題
sudo /opt/gitlab/embedded/sbin/nginx -t -c /var/opt/gitlab/nginx/conf/nginx.conf

 

# pages 需要搭配 runner

# 確認 GitLab Runner 可用
## Pages 需要 GitLab CI/CD pipeline 成功執行,所以你要有 Runner
### 到 GitLab 後台或專案確認:
Admin Area > CI/CD > Runners
### 或專案:
Settings > CI/CD > Runners
↑ 兩個的差別是各自專案可以自行建立 runner ,而 admin 是可以給大家用,但都要進 ssh console 註冊 runner
所以 gitlab 上要先安裝 runner
# 安裝 CI Runner

 

curl -L "https://packages.gitlab.com/install/repositories/runner/gitlab-runner/script.deb.sh" | bash

apt update

apt-get install gitlab-runner

 

# 或

# install gitlab runner

# Download the binary for your system
sudo curl -L --output /usr/local/bin/gitlab-runner https://gitlab-runner-downloads.s3.amazonaws.com/latest/binaries/gitlab-runner-linux-amd64

# Give it permission to execute
sudo chmod +x /usr/local/bin/gitlab-runner

# Create a GitLab Runner user
sudo useradd --comment 'GitLab Runner' --create-home gitlab-runner --shell /bin/bash

# Install and run as a service
sudo gitlab-runner install --user=gitlab-runner --working-directory=/home/gitlab-runner
sudo gitlab-runner start

 

# 註冊 CI Runner (shell)
# 純 html

gitlab-runner register --url https://git.ssorc.tw --token glrt-xxxxxxxxxxxxxxxxxx.01.1801pgcp4 \
--executor shell \
--tls-ca-file /etc/gitlab/ssl/server.crt


# 使用 docker / npm
# tags global,pages,npm

gitlab-runner register --url https://git.ssorc.tw --token glrt-xxxxxxxxxxxxxxxxxxxx.01.121u6vnn2 \
--executor docker \
--docker-image node:20 \
--description "global-pages-npm-runner" \
--tls-ca-file /etc/gitlab/ssl/server.crt


sudo systemctl restart gitlab-runner
接著在 gitlab 上建立 group/project
然後 clone 到本機
再建立一個 .gitlab-ci.yml  (就是靠它讓 gitlab 知道要 build 什麼)
也可以參考 https://gitlab.com/pages/plain-html
目錄結構會長這樣子 ↓
my-project/
├─ public/
│  └─ index.html
└─ .gitlab-ci.yml
# public/index.html (瀏覽 pages.ssorc.tw/cross/testpages/ 時看到的內容)
<!doctype html>
<html>
  <head>
    <meta charset="utf-8">
    <title>GitLab Pages Test</title>
  </head>
  <body>
    <h1>Hello GitLab Pages</h1>
  </body>
</html>
# .gitlab-ci.yml (讓 gitlab ci/cd 靠它知道要怎麼做事)
image: busybox
pages:
  tags:
    - pages
  stage: deploy
  script:
    - echo "The site will be deployed to $CI_PAGES_URL"
  artifacts:
    paths:
      - public
  rules:
    - if: $CI_COMMIT_BRANCH == $CI_DEFAULT_BRANCH

↑ 編輯完後, git push 到 gitlab

就可在 gitlab 的 build > pipelines 重確認有沒有佈署成功

成功的話在 pages.ssorc.tw/cross/testpages 上可以看到佈署的網頁

 

 

 

Q
Running handlers:
[2026-05-17T19:08:01+08:00] ERROR: Running exception handlers
There was an error running gitlab-ctl reconfigure:

letsencrypt_certificate[git.ssorc.tw] (letsencrypt::http_authorization line 6) had an error: RuntimeError: acme_certificate[staging] (letsencrypt::http_authorization line 60) had an error: RuntimeError: ruby_block[create certificate for git.ssorc.tw] (letsencrypt::http_authorization line 112) had an error: RuntimeError: [git.ssorc.tw] Validation failed, unable to request certificate, Errors: [{url: https://acme-staging-v02.api.letsencrypt.org/acme/chall/293165773/1336776933/zmrQwg, status: invalid, error: {“type”=>”urn:ietf:params:acme:error:dns”, “detail”=>”DNS problem: NXDOMAIN looking up A for git.ssorc.tw – check that a DNS record exists for this domain; DNS problem: NXDOMAIN looking up AAAA for git.ssorc.tw – check that a DNS record exists for this domain”, “status”=>400}} ]

Running handlers complete
[2026-05-17T19:08:01+08:00] ERROR: Exception handlers complete
Infra Phase failed. 5 resources updated in 14 seconds
[2026-05-17T19:08:01+08:00] FATAL: Stacktrace dumped to /opt/gitlab/embedded/cookbooks/cache/cinc-stacktrace.out
[2026-05-17T19:08:01+08:00] FATAL: —————————————————————————————
[2026-05-17T19:08:01+08:00] FATAL: PLEASE PROVIDE THE CONTENTS OF THE stacktrace.out FILE (above) IF YOU FILE A BUG REPORT
[2026-05-17T19:08:01+08:00] FATAL: —————————————————————————————
[2026-05-17T19:08:01+08:00] FATAL: RuntimeError: letsencrypt_certificate[git.ssorc.tw] (letsencrypt::http_authorization line 6) had an error: RuntimeError: acme_certificate[staging] (letsencrypt::http_authorization line 60) had an error: RuntimeError: ruby_block[create certificate for git.ssorc.tw] (letsencrypt::http_authorization line 112) had an error: RuntimeError: [git.ssorc.tw] Validation failed, unable to request certificate, Errors: [{url: https://acme-staging-v02.api.letsencrypt.org/acme/chall/293165773/1336776933/zmrQwg, status: invalid, error: {“type”=>”urn:ietf:params:acme:error:dns”, “detail”=>”DNS problem: NXDOMAIN looking up A for git.ssorc.tw – check that a DNS record exists for this domain; DNS problem: NXDOMAIN looking up AAAA for git.ssorc.tw – check that a DNS record exists for this domain”, “status”=>400}} ]

A
# 不要讓 GitLab 自動申請 Let’s Encrypt
letsencrypt[‘enable’] = false

Q
為什麼使用了 https 但是 pages 卻 502 Whoops, something went wrong on our end.

A
gitlab-pages 無法驗證 GitLab 主站憑證

sudo tail -n 100 /var/log/gitlab/gitlab-pages/current

看到類似:

x509: certificate signed by unknown authority

或:

failed to connect to internal Pages API

就加這個設定:

gitlab_pages[‘internal_gitlab_server’] = “https://git.ssorc.tw”
gitlab_pages[‘internal_gitlab_server_cert’] = “/etc/gitlab/ssl/ca.crt”

# 或
gitlab_pages[‘internal_gitlab_server’] = “http://127.0.0.1:8080”

 

 

Related posts 相關文章
GitLab 17.7 使用 openssl 3 與 tls 1.2
More...
gitlab-ce 升級到 17.0.0 後續
More...
gitlab-ce 升級到 17.0.0 就壞掉了
More...
gitlab 出現 cannot unblock ldap blocked users 問題
More...

作者

留言

撰寫回覆或留言

發佈留言必須填寫的電子郵件地址不會公開。