在 CentOS 上给 Jenkins 配置 SSL(HTTPS),常见有三种方式,按推荐程度如下:
适合生产环境,Jenkins 本身不处理 SSL,由 Nginx 处理
yum install -y nginx
systemctl enable nginx
systemctl start nginx
yourdomain.crt + yourdomain.keyyum install -y certbot
certbot certonly --nginx -d jenkins.example.com
server {
listen 443 ssl;
server_name jenkins.example.com;
ssl_certificate /etc/nginx/ssl/jenkins.crt;
ssl_certificate_key /etc/nginx/ssl/jenkins.key;
location / {
proxy_pass http://127.0.0.1:8080;
proxy_set_header Host $host;
proxy_set_header X-Real-IP $remote_addr;
proxy_set_header X-Forwarded-For $proxy_add_x_forwarded_for;
proxy_set_header X-Forwarded-Proto $scheme;
}
}
server {
listen 80;
server_name jenkins.example.com;
return 301 https://$host$request_uri;
}
vi /etc/sysconfig/jenkins
JENKINS_ARGS="--httpListenAddress=127.0.0.1"
systemctl restart jenkins
systemctl restart nginx
openssl req -x509 -newkey rsa:2048 \
-keyout key.pem -out cert.pem -days 365 -nodes
openssl pkcs12 -export \
-in cert.pem -inkey key.pem \
-out jenkins.p12 -name jenkins
vi /etc/sysconfig/jenkins
JENKINS_ARGS="--httpsPort=8443 --httpsKeyStore=/var/lib/jenkins/jenkins.p12 --httpsKeyStorePassword=changeit"
systemctl restart jenkins
访问:
https://ip:8443
⚠️ 配置复杂,兼容性差,不推荐生产使用
如果你更熟悉 Apache:
yum install httpd mod_ssl
使用 ProxyPass + SSL 配置
curl -I https://jenkins.example.com
在 Jenkins → 系统配置 → Jenkins URL
https://jenkins.example.com/
firewall-cmd --add-port=443/tcp --permanent
firewall-cmd --reload
如果你告诉我:
我可以给你完全定制的配置。