From cc7219539d2e26d461dba2f5d727778f1e704e37 Mon Sep 17 00:00:00 2001 From: zk Date: Thu, 28 May 2026 09:43:03 +0800 Subject: [PATCH] =?UTF-8?q?=E8=B7=9F=E6=96=B0=20nginx=20=E6=B5=81=E9=87=8F?= =?UTF-8?q?=E5=88=87=E6=8D=A2=E6=96=B9=E5=BC=8F?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- Jenkinsfile | 8 ++++---- docker-compose.yml | 2 -- 2 files changed, 4 insertions(+), 6 deletions(-) diff --git a/Jenkinsfile b/Jenkinsfile index 1a7e35e..3fc7500 100644 --- a/Jenkinsfile +++ b/Jenkinsfile @@ -60,9 +60,7 @@ pipeline { echo "传输文件到目标服务器" sh "${SSH_CMD} 'mkdir -p ${REMOTE_DIR}'" sh "${SCP_CMD} ${IMAGE_NAME}.tar ${DEPLOY_USER}@${DEPLOY_HOST}:${REMOTE_DIR}/" - // 传输 nginx.conf(用 cat 写入保持 inode,避免 bind mount 失效) - sh "${SCP_CMD} nginx.conf ${DEPLOY_USER}@${DEPLOY_HOST}:${REMOTE_DIR}/nginx.conf.tmp" - sh "${SSH_CMD} 'cat ${REMOTE_DIR}/nginx.conf.tmp > ${REMOTE_DIR}/nginx.conf && rm -f ${REMOTE_DIR}/nginx.conf.tmp'" + sh "${SCP_CMD} nginx.conf ${DEPLOY_USER}@${DEPLOY_HOST}:${REMOTE_DIR}/nginx.conf" sh "${SCP_CMD} docker-compose.yml ${DEPLOY_USER}@${DEPLOY_HOST}:${REMOTE_DIR}/docker-compose.yml" } } @@ -128,6 +126,8 @@ pipeline { } echo "Nginx 容器已存在且运行中" } + // docker cp nginx.conf 进容器 + sh "${SSH_CMD} 'docker cp ${REMOTE_DIR}/nginx.conf ${CONTAINER_PREFIX}-nginx:/etc/nginx/nginx.conf'" } } } @@ -163,7 +163,7 @@ pipeline { stage('切换流量') { steps { script { - sh "${SSH_CMD} \"sed -i 's/proxy_pass http:\\/\\/\\(blue\\|green\\):8000;/proxy_pass http:\\/\\/${env.DEPLOY_TARGET}:8000;/' ${REMOTE_DIR}/nginx.conf\"" + sh "${SSH_CMD} 'docker exec ${CONTAINER_PREFIX}-nginx sed -i \"s/proxy_pass http:\\/\\/\\(blue\\|green\\):8000;/proxy_pass http:\\/\\/${env.DEPLOY_TARGET}:8000;/\" /etc/nginx/nginx.conf'" sh "${SSH_CMD} 'docker exec ${CONTAINER_PREFIX}-nginx nginx -s reload'" echo "✅ 流量已切换到 ${env.DEPLOY_TARGET}" } diff --git a/docker-compose.yml b/docker-compose.yml index 818b510..1817e83 100644 --- a/docker-compose.yml +++ b/docker-compose.yml @@ -5,8 +5,6 @@ services: restart: unless-stopped ports: - "10502:80" - volumes: - - ./nginx.conf:/etc/nginx/nginx.conf:ro healthcheck: test: ["CMD", "wget", "--spider", "-q", "http://localhost/health"] interval: 30s