在Debian上为Jenkins配置SSL证书(以Let’s Encrypt为例)
确保系统已安装Java(Jenkins依赖)和certbot(证书管理工具):
sudo apt update sudo apt install openjdk-11-jdk certbot -y 使用Certbot获取免费SSL证书(以yourdomain.com替换为你的域名):
sudo certbot certonly --standalone -d yourdomain.com --standalone:Certbot会启动一个临时Web服务器完成域名验证(需确保80端口未被占用)。/etc/letsencrypt/live/yourdomain.com/,包含: fullchain.pem(证书链,需配置到Jenkins的Keystore)privkey.pem(私钥,需配置到Jenkins的私钥路径)。http://yourdomain.com:8080)。/etc/letsencrypt/live/yourdomain.com/fullchain.pem。sudo nano /etc/default/jenkins JENKINS_ARGS行,修改为以下内容(替换域名):JENKINS_ARGS="--httpPort=-1 --httpsPort=8443 --httpsCertificate=/etc/letsencrypt/live/yourdomain.com/fullchain.pem --httpsPrivateKey=/etc/letsencrypt/live/yourdomain.com/privkey.pem" --httpPort=-1:禁用HTTP端口(强制使用HTTPS)。--httpsPort=8443:设置HTTPS端口(可自定义,如443需root权限)。Ctrl+O→Enter→Ctrl+X)。sudo systemctl restart jenkins 打开浏览器访问https://yourdomain.com:8443(若修改了端口需对应调整),确认:
Let’s Encrypt证书有效期为90天,需设置自动续期:
sudo certbot renew --dry-run echo "0 2 * * * certbot renew --quiet --post-hook 'systemctl restart jenkins'" | sudo tee /etc/cron.d/certbot-jenkins > /dev/null --post-hook:续期后自动重启Jenkins,加载新证书。