Gitlab配置https认证(snapd创建SSL证书)
环境准备#
- 一台centos 7 LInux操作系统主机,并且能够
正常上网
- 需要申请一个域名
安装snapd#
官网地址:https://certbot.eff.org
[root@snapd ~]# yum -y install epel-release
[root@snapd ~]# yum makecache fast
[root@snapd ~]# yum -y install snapd
[root@snapd ~]# systemctl enable --now snapd #启动并设置开机自启
[root@snapd ~]# ln -s /var/lib/snapd/snap /snap #设置软连接
[root@snapd ~]# snap --help #检测一下
The snap command lets you install, configure, refresh and remove snaps.
Snaps are packages that work across many different Linux distributions,
enabling secure delivery and operation of the latest apps and utilities.
Usage: snap <command> [<options>...]
# 安装Certbot软件包,并使用了--classic标志(经典模式)
[root@snapd ~]# snap install --classic certbot
2024-09-16T04:57:12+08:00 INFO Waiting for automatic snapd restart...
Warning: /var/lib/snapd/snap/bin was not found in your $PATH. If you've not restarted your session
since you installed snapd, try doing that. Please see https://forum.snapcraft.io/t/9469
for more details.
certbot 2.11.0 from Certbot Project (certbot-eff✓) installed
生成解析记录#
[root@snapd ~]# ln -s /snap/bin/certbot /usr/bin/certbot #设置certbot软链接
[root@snapd ~]# certbot certonly --manual --preferred-challenges dns -d *.bforest.top
# certbot certonly --manual --preferred-challenges dns -d *.bforest.top 这条命令用于使用Certbot工具获取SSL/TLS证书。
# 具体解释如下:
certbot: 是Certbot的命令行工具,用于管理SSL/TLS证书。
certonly: 表示只获取证书而不配置自动更新和续订。
--manual: 指定手动验证模式,即通过手动创建验证文件来证明域名所有权。
--preferred-challenges dns: 指定首选的验证方式为DNS(DNS challenge),即通过在DNS记录中添加特定的TXT记录来证明域名所有权。
-d bforest.top: 指定要获取证书的域名,这里包括bforest.top和以*.bforest.top开头的所有子域名。
综上所述,该命令的作用是使用Certbot工具,通过手动验证模式和DNS挑战方式,为bforest.top和以*.bforest.top开头的所有子域名获取SSL/TLS证书。



安装gitlab#
配置SSL证书(以Gitlab为例)#
配置阿里云域名正向解析
![]()
# 创建SSL证书存放路径
[root@snapd ~]# mkdir /etc/gitlab/ssl
[root@snapd ~]# ls /etc/letsencrypt/live/bforest.top/
cert.pem chain.pem fullchain.pem privkey.pem README
# 将制作的证书和私钥放到/etc/gitlab/ssl
[root@snapd ~]# ls /etc/gitlab/ssl/
fullchain.pem privkey.pem
### 修改配置文件
[root@snapd ~]# vim /etc/gitlab/gitlab.rb
# 定义 GitLab 实例的外部访问 URL。用户通过此 URL 访问 GitLab 界面。
external_url 'https://gitlab.bforest.top'
# 设置 GitLab 的时区为 "Asia/Shanghai"。这影响到 GitLab 中时间显示的区域设置。
gitlab_rails['time_zone'] = 'Asia/Shanghai'
# 定义 Git 数据存储的路径。
git_data_dirs({
"default" => {
"path" => "/mnt/nfs-01/git-data"
}
})
# 设置 GitLab Shell 使用的 SSH 端口。
gitlab_rails['gitlab_shell_ssh_port'] = 22
# 启用 Nginx,GitLab 使用 Nginx 作为 Web 服务器。
nginx['enable'] = true
# 设置最大请求体大小为 250MB
nginx['client_max_body_size'] = '250m'
# 启用 HTTP 到 HTTPS 的重定向,确保所有流量通过 HTTPS。
nginx['redirect_http_to_https'] = true
# 设置重定向端口为 80。
nginx['redirect_http_to_https_port'] = 80
# 指定 SSL 证书和密钥的位置,用于 HTTPS。
nginx['ssl_certificate'] = "/etc/gitlab/ssl/fullchain.pem"
nginx['ssl_certificate_key'] = "/etc/gitlab/ssl/privkey.pem"
nginx['ssl_ciphers'] = "ECDHE-ECDSA-AES128-GCM-SHA256:ECDHE-RSA-AES128-GCM-SHA256:ECDHE-ECDSA-AES256-GCM-SHA384:ECDHE-RSA-AES256-GCM-SHA384:ECDHE-ECDSA-CHACHA20-POLY1305:ECDHE-RSA-CHACHA20-POLY1305:DHE-RSA-AES128-GCM-SHA256:DHE-RSA-AES256-GCM-SHA384"
nginx['ssl_prefer_server_ciphers'] = "off"
# 定义支持的 SSL/TLS 协议版本。
nginx['ssl_protocols'] = "TLSv1.2 TLSv1.3"
# 配置 SSL 会话缓存,提高性能。
nginx['ssl_session_cache'] = "shared:SSL:10m"
# 超时时间。
nginx['ssl_session_timeout'] = "1d"
# 启用 Gzip 压缩,提高传输效率。
nginx['gzip_enabled'] = true
重新加载gitlab并测试#
[root@snapd ~]# gitlab-ctl reconfigure
本地解析位置:C:\Windows\System32\drivers\etc\hosts




完成!
【推荐】编程新体验,更懂你的AI,立即体验豆包MarsCode编程助手
【推荐】凌霞软件回馈社区,博客园 & 1Panel & Halo 联合会员上线
【推荐】抖音旗下AI助手豆包,你的智能百科全书,全免费不限次数
【推荐】博客园社区专享云产品让利特惠,阿里云新客6.5折上折
【推荐】轻量又高性能的 SSH 工具 IShell:AI 加持,快人一步
· 一个费力不讨好的项目,让我损失了近一半的绩效!
· 清华大学推出第四讲使用 DeepSeek + DeepResearch 让科研像聊天一样简单!
· 实操Deepseek接入个人知识库
· CSnakes vs Python.NET:高效嵌入与灵活互通的跨语言方案对比
· Plotly.NET 一个为 .NET 打造的强大开源交互式图表库