87 lines
3.1 KiB
Bash
87 lines
3.1 KiB
Bash
#!/bin/bash
|
|
|
|
# 修复Jenkins Nginx配置 - 更新webhook路径
|
|
|
|
# 在服务器上执行此脚本
|
|
|
|
# 1. 备份当前配置
|
|
docker cp novalon-nginx-secure:/etc/nginx/nginx.conf /tmp/nginx.conf.bak
|
|
|
|
# 2. 创建新的Jenkins配置
|
|
cat > /tmp/jenkins-server.conf << 'EOF'
|
|
# Jenkins CI/CD Server
|
|
server {
|
|
listen 80;
|
|
server_name ci.f.novalon.cn;
|
|
return 301 https://$host$request_uri;
|
|
}
|
|
|
|
server {
|
|
listen 443 ssl http2;
|
|
server_name ci.f.novalon.cn;
|
|
|
|
ssl_certificate /etc/nginx/ssl/ci.f.novalon.cn/fullchain.pem;
|
|
ssl_certificate_key /etc/nginx/ssl/ci.f.novalon.cn/privkey.pem;
|
|
ssl_protocols TLSv1.2 TLSv1.3;
|
|
ssl_ciphers ECDHE-RSA-AES128-GCM-SHA256:ECDHE-RSA-AES256-GCM-SHA384:ECDHE-RSA-CHACHA20-POLY1305;
|
|
ssl_prefer_server_ciphers off;
|
|
ssl_session_cache shared:SSL:10m;
|
|
ssl_session_timeout 1d;
|
|
|
|
add_header Strict-Transport-Security "max-age=63072000; includeSubDomains; preload" always;
|
|
add_header X-Frame-Options "SAMEORIGIN" always;
|
|
add_header X-Content-Type-Options "nosniff" always;
|
|
add_header X-XSS-Protection "1; mode=block" always;
|
|
|
|
# Jenkins webhook端点 - 直接代理到Jenkins根路径
|
|
location /generic-webhook-trigger/ {
|
|
proxy_pass http://172.17.0.1:8080/generic-webhook-trigger/;
|
|
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;
|
|
client_max_body_size 100m;
|
|
proxy_connect_timeout 60s;
|
|
proxy_send_timeout 60s;
|
|
proxy_read_timeout 60s;
|
|
proxy_http_version 1.1;
|
|
proxy_set_header Upgrade $http_upgrade;
|
|
proxy_set_header Connection "upgrade";
|
|
}
|
|
|
|
# Jenkins主应用
|
|
location /jenkins/ {
|
|
proxy_pass http://172.17.0.1:8080/jenkins/;
|
|
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;
|
|
client_max_body_size 100m;
|
|
proxy_connect_timeout 60s;
|
|
proxy_send_timeout 60s;
|
|
proxy_read_timeout 60s;
|
|
proxy_http_version 1.1;
|
|
proxy_set_header Upgrade $http_upgrade;
|
|
proxy_set_header Connection "upgrade";
|
|
}
|
|
|
|
# 默认location - 重定向到/jenkins/
|
|
location / {
|
|
return 301 https://$host/jenkins/;
|
|
}
|
|
|
|
access_log /var/log/nginx/jenkins-access.log;
|
|
error_log /var/log/nginx/jenkins-error.log;
|
|
}
|
|
EOF
|
|
|
|
# 3. 替换Jenkins配置部分
|
|
sed -i '/# Jenkins CI\/CD Server/,/^ }$/d' /tmp/nginx.conf.bak
|
|
sed -i "/^}/i $(cat /tmp/jenkins-server.conf)" /tmp/nginx.conf.bak
|
|
|
|
# 4. 复制回容器并重载
|
|
docker cp /tmp/nginx.conf.bak novalon-nginx-secure:/etc/nginx/nginx.conf
|
|
docker exec novalon-nginx-secure nginx -t && docker exec novalon-nginx-secure nginx -s reload
|
|
|
|
echo "Jenkins Nginx配置已更新"
|