Ubuntu 上 Jenkins 代理配置全指南
在 Ubuntu 环境中,Jenkins 的“代理”常见有三类场景:一是为 Jenkins 本身设置HTTP/HTTPS 出站代理以下载插件与依赖;二是用 Nginx 做反向代理与 SSL 终止;三是将 **Ubuntu 机器作为 Jenkins 的代理节点(Agent)**来扩展构建能力。下面分别给出可操作步骤与要点。
一 为 Jenkins 设置 HTTP 出站代理
二 使用 Nginx 作为反向代理并启用 SSL
server {
listen 80;
server_name jenkins.example.com;
return 301 https://$host$request_uri;
}
server {
listen 443 ssl http2;
server_name jenkins.example.com;
ssl_certificate /etc/letsencrypt/live/jenkins.example.com/fullchain.pem;
ssl_certificate_key /etc/letsencrypt/live/jenkins.example.com/privkey.pem;
access_log /var/log/nginx/jenkins.access.log;
error_log /var/log/nginx/jenkins.error.log;
location / {
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;
proxy_pass http://127.0.0.1:8080;
proxy_read_timeout 90;
proxy_redirect http://localhost:8080 https://jenkins.example.com;
}
}
三 将 Ubuntu 作为 Jenkins 代理节点 Agent
wget http://<JENKINS_URL>/jnlpJars/agent.jar
java -jar agent.jar -jnlpUrl http://<JENKINS_URL>/computer/<NODE_NAME>/jenkins-agent.jnlp -secret <SECRET> -workDir "/var/jenkins"
四 常见问题与排查