Help us learn about your current experience with the documentation. Take the survey.
使用 dnsmasq 动态处理 GitLab Pages 子域名
您可以使用 dnsmasq 在本地测试 GitLab Pages 网站,而无需在 /etc/hosts 中为每个站点进行配置。
在 macOS 上使用 dnsmasq
要在 macOS 上使用 dnsmasq:
- 安装
dnsmasq:
brew install dnsmasq
- 设置
*.test域名解析:
# 确保配置目录存在
mkdir -p $(brew --prefix)/etc/
# 将 `*.test` 添加到 `127.0.0.1` 解析
echo 'address=/.test/127.0.0.1' >> $(brew --prefix)/etc/dnsmasq.conf
# 启动 `dnsmasq`
sudo brew services start dnsmasq
- 创建 DNS 解析器:
# 确保解析器目录存在
sudo mkdir -p /etc/resolver
# 将本地地址添加为 `.test` 域名的解析器
echo "nameserver 127.0.0.1" | sudo tee /etc/resolver/test
现在您可以使用动态域名在本地创建 GitLab Pages 网站。
如果您 配置 GitLab Pages 并创建一个 root/html 项目,该项目可以通过 http://root.gdk.pages.test:3010/html 访问。
故障排除
对于 GitLab Runner,您必须在 /etc/hosts 中定义 gdk.test。
如果您在本地使用 GitLab Runner,还必须配置 /etc/hosts:
# 在 `/etc/hosts` 中追加 GDK 配置
cat <<-EOF | sudo tee -a /etc/hosts
## GDK
127.0.0.1 gdk.test
::1 gdk.test
# ----------------------------
EOF