在 CentOS 上让 Jenkins 通过域名访问,通常做法是:
Jenkins(自带端口,如 8080) + Nginx 反向代理 + 域名解析
下面按步骤说明。
jenkins.example.com)在你的域名服务商处添加解析:
Ajenkins例如:
jenkins.example.com → 1.2.3.4
sudo yum install -y epel-release
sudo yum install -y nginx
sudo systemctl enable nginx
sudo systemctl start nginx
sudo vi /etc/nginx/conf.d/jenkins.conf
写入以下内容(注意修改域名):
server {
listen 80;
server_name jenkins.example.com;
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;
}
}
sudo nginx -t
sudo systemctl reload nginx
此时访问:
http://jenkins.example.com
应可打开 Jenkins。
sudo yum install -y certbot python2-certbot-nginx
sudo certbot --nginx -d jenkins.example.com
按提示操作,证书会自动配置。
进入:
Jenkins → 系统管理 → 系统配置
设置:
Jenkins URL: https://jenkins.example.com/
sudo vi /etc/sysconfig/jenkins
修改:
JENKINS_LISTEN_ADDRESS="127.0.0.1"
重启:
sudo systemctl restart jenkins
sudo firewall-cmd --permanent --add-service=http
sudo firewall-cmd --permanent --add-service=https
sudo firewall-cmd --reload
如果你需要:
可以告诉我你的具体环境。