fix: 适配新服务器蓝绿部署 — nginx 原生/PostgreSQL Docker 容器名/部署脚本
Some checks failed
Deploy Backend / deploy (push) Has been cancelled
Some checks failed
Deploy Backend / deploy (push) Has been cancelled
This commit is contained in:
@@ -12,11 +12,9 @@ PROJECT_ROOT="$(dirname "$SCRIPT_DIR")"
|
||||
ENV_FILE="$PROJECT_ROOT/.env"
|
||||
|
||||
# ---------- 配置 ----------
|
||||
# 1Panel 管理的 OpenResty 容器的实际配置文件路径
|
||||
# 容器内路径(host: /opt/1panel/apps/openresty/openresty/www/sites/...)
|
||||
ROOT_CONF="/www/sites/xmclassmate.top/proxy/root.conf"
|
||||
NGINX_CONTAINER="1Panel-openresty-ABu5"
|
||||
SSH_HOST="root@1panel-server"
|
||||
NGINX_SSL_CONF="/www/sites/xmclassmate.top/ssl/fullchain.pem"
|
||||
SSH_HOST="deploy@47.109.203.92"
|
||||
|
||||
# ---------- 颜色输出 ----------
|
||||
RED='\033[0;31m'; GREEN='\033[0;32m'; YELLOW='\033[1;33m'; BLUE='\033[0;34m'; NC='\033[0m'
|
||||
@@ -41,7 +39,7 @@ usage() {
|
||||
|
||||
# ---------- 获取当前活动环境 ----------
|
||||
get_active() {
|
||||
local proxy_conf; proxy_conf=$(ssh "$SSH_HOST" "docker exec ${NGINX_CONTAINER} cat ${ROOT_CONF}" 2>/dev/null || echo "")
|
||||
local proxy_conf; proxy_conf=$(ssh "$SSH_HOST" "sudo cat ${ROOT_CONF}" 2>/dev/null || echo "")
|
||||
if echo "$proxy_conf" | grep -q "127.0.0.1:4433"; then
|
||||
echo "blue"
|
||||
elif echo "$proxy_conf" | grep -q "127.0.0.1:4434"; then
|
||||
@@ -104,15 +102,15 @@ switch_to() {
|
||||
|
||||
# 修改 proxy_pass(两个端口都是 HTTPS)
|
||||
local target_proto="https"
|
||||
info "修改 OpenResty proxy_pass → ${target_proto}://127.0.0.1:${target_port}..."
|
||||
ssh "$SSH_HOST" "docker exec ${NGINX_CONTAINER} sh -c \"sed -i 's|proxy_pass https\?://127.0.0.1:[0-9]*|proxy_pass ${target_proto}://127.0.0.1:${target_port}|' ${ROOT_CONF}\"" 2>&1 || {
|
||||
info "修改 nginx proxy_pass → ${target_proto}://127.0.0.1:${target_port}..."
|
||||
ssh "$SSH_HOST" "sudo sed -i 's|proxy_pass https\?://127.0.0.1:[0-9]*|proxy_pass ${target_proto}://127.0.0.1:${target_port}|' ${ROOT_CONF}" 2>&1 || {
|
||||
error "修改 proxy_pass 失败"
|
||||
exit 1
|
||||
}
|
||||
|
||||
# 重新加载 nginx
|
||||
info "重新加载 nginx..."
|
||||
ssh "$SSH_HOST" "docker exec ${NGINX_CONTAINER} nginx -s reload" 2>&1 || {
|
||||
ssh "$SSH_HOST" "sudo nginx -s reload" 2>&1 || {
|
||||
error "nginx 重载失败"
|
||||
exit 1
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user