迁移的一些脚本文件

This commit is contained in:
2026-07-21 00:01:50 +08:00
parent cf73bbae23
commit 47b39e3ba0
9 changed files with 259 additions and 15 deletions
+47
View File
@@ -0,0 +1,47 @@
#!/usr/bin/env bash
# 启用 api.dukanghaoke.com:扩证书 + 装 nginx 配置
set -euo pipefail
DOMAIN_API=api.dukanghaoke.com
CERT_NAME=user.dukanghaoke.com
EMAIL="${CERTBOT_EMAIL:-admin@dukanghaoke.com}"
APP_ROOT="${APP_ROOT:-/opt/dukang}"
NGINX_SRC="$APP_ROOT/deploy/nginx-dukanghaoke.conf"
NGINX_DST="/etc/nginx/sites-available/dukang"
mkdir -p /var/www/certbot/.well-known/acme-challenge
mkdir -p /var/log/nginx/dukang
echo "==> 1. 临时 HTTP 放行 api 域名(便于 http-01"
# 先写入含 api 的 80 server,若证书尚未含 api,443 块可暂用现有证书
if [[ -f "$NGINX_SRC" ]]; then
install -m 644 "$NGINX_SRC" "$NGINX_DST"
ln -sfn "$NGINX_DST" /etc/nginx/sites-enabled/dukang
fi
nginx -t
systemctl reload nginx
echo "==> 2. 扩展证书加入 $DOMAIN_API"
certbot certonly --nginx \
--cert-name "$CERT_NAME" \
--expand \
-d user.dukanghaoke.com \
-d shop.dukanghaoke.com \
-d partner.dukanghaoke.com \
-d admin.dukanghaoke.com \
-d api.dukanghaoke.com \
--email "$EMAIL" \
--agree-tos \
--non-interactive \
--keep-until-expiring
echo "==> 3. 重载 nginx"
nginx -t
systemctl reload nginx
echo "==> 4. 健康检查"
sleep 1
curl -sf -o /dev/null -w "api-https:%{http_code} content-type:%{content_type}\n" \
"https://${DOMAIN_API}/api/v1/health"
curl -sf "https://${DOMAIN_API}/api/v1/health"; echo
echo "==> 完成"
+1 -1
View File
@@ -1,4 +1,4 @@
# 杜康好客 — CodeUp Webhook 反代(挂到 dkapi.runxian.top 443/80 server 块内)
# 杜康好客 — CodeUp Webhook 反代(挂到 api.dukanghaoke.com 443/80 server 块内)
# setup-webhook.sh 会自动 include 此文件
location = /hooks/deploy {
+185
View File
@@ -0,0 +1,185 @@
# 杜康好客 — dukanghaoke.com
# HTTP → HTTPS
server {
listen 80;
server_name user.dukanghaoke.com shop.dukanghaoke.com partner.dukanghaoke.com admin.dukanghaoke.com api.dukanghaoke.com;
location ^~ /.well-known/acme-challenge/ {
root /var/www/certbot;
default_type "text/plain";
}
location / {
return 301 https://$host$request_uri;
}
}
# api.dukanghaoke.com → 8090
server {
listen 443 ssl;
http2 on;
server_name api.dukanghaoke.com;
ssl_certificate /etc/letsencrypt/live/user.dukanghaoke.com/fullchain.pem;
ssl_certificate_key /etc/letsencrypt/live/user.dukanghaoke.com/privkey.pem;
ssl_protocols TLSv1.2 TLSv1.3;
ssl_ciphers HIGH:!aNULL:!MD5;
client_max_body_size 50m;
include /opt/dukang/deploy/nginx-deploy-webhook.conf;
location / {
proxy_pass http://127.0.0.1:8090;
proxy_http_version 1.1;
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_set_header Connection "";
}
}
# user.dukanghaoke.com → 8091
server {
listen 443 ssl;
http2 on;
server_name user.dukanghaoke.com;
ssl_certificate /etc/letsencrypt/live/user.dukanghaoke.com/fullchain.pem;
ssl_certificate_key /etc/letsencrypt/live/user.dukanghaoke.com/privkey.pem;
ssl_protocols TLSv1.2 TLSv1.3;
ssl_ciphers HIGH:!aNULL:!MD5;
client_max_body_size 50m;
location /api/ {
proxy_pass http://127.0.0.1:8090;
proxy_http_version 1.1;
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_set_header Connection "";
}
location / {
proxy_pass http://127.0.0.1:8091;
proxy_http_version 1.1;
proxy_set_header Upgrade $http_upgrade;
proxy_set_header Connection 'upgrade';
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_cache_bypass $http_upgrade;
}
}
# shop.dukanghaoke.com → 8092
server {
listen 443 ssl;
http2 on;
server_name shop.dukanghaoke.com;
ssl_certificate /etc/letsencrypt/live/user.dukanghaoke.com/fullchain.pem;
ssl_certificate_key /etc/letsencrypt/live/user.dukanghaoke.com/privkey.pem;
ssl_protocols TLSv1.2 TLSv1.3;
ssl_ciphers HIGH:!aNULL:!MD5;
client_max_body_size 50m;
location /api/ {
proxy_pass http://127.0.0.1:8090;
proxy_http_version 1.1;
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_set_header Connection "";
}
location / {
proxy_pass http://127.0.0.1:8092;
proxy_http_version 1.1;
proxy_set_header Upgrade $http_upgrade;
proxy_set_header Connection 'upgrade';
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_cache_bypass $http_upgrade;
}
}
# partner.dukanghaoke.com → 8093
server {
listen 443 ssl;
http2 on;
server_name partner.dukanghaoke.com;
ssl_certificate /etc/letsencrypt/live/user.dukanghaoke.com/fullchain.pem;
ssl_certificate_key /etc/letsencrypt/live/user.dukanghaoke.com/privkey.pem;
ssl_protocols TLSv1.2 TLSv1.3;
ssl_ciphers HIGH:!aNULL:!MD5;
client_max_body_size 50m;
location /api/ {
proxy_pass http://127.0.0.1:8090;
proxy_http_version 1.1;
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_set_header Connection "";
}
location / {
proxy_pass http://127.0.0.1:8093;
proxy_http_version 1.1;
proxy_set_header Upgrade $http_upgrade;
proxy_set_header Connection 'upgrade';
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_cache_bypass $http_upgrade;
}
}
# admin.dukanghaoke.com → 8094
server {
listen 443 ssl;
http2 on;
server_name admin.dukanghaoke.com;
ssl_certificate /etc/letsencrypt/live/user.dukanghaoke.com/fullchain.pem;
ssl_certificate_key /etc/letsencrypt/live/user.dukanghaoke.com/privkey.pem;
ssl_protocols TLSv1.2 TLSv1.3;
ssl_ciphers HIGH:!aNULL:!MD5;
client_max_body_size 50m;
location /api/ {
proxy_pass http://127.0.0.1:8090;
proxy_http_version 1.1;
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_set_header Connection "";
}
location / {
proxy_pass http://127.0.0.1:8094;
proxy_http_version 1.1;
proxy_set_header Upgrade $http_upgrade;
proxy_set_header Connection 'upgrade';
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_cache_bypass $http_upgrade;
}
}
+1 -1
View File
@@ -47,7 +47,7 @@ export NODE_OPTIONS="${NODE_OPTIONS:---max-old-space-size=8192}"
export TARO_H5_PUBLIC_PATH="${TARO_H5_PUBLIC_PATH:-/user/}"
export TARO_H5_ROUTER_BASENAME="${TARO_H5_ROUTER_BASENAME:-/user}"
# C 端 H5 编译期注入的 API origin(勿落到 localhost
export VITE_API_TARGET="${VITE_API_TARGET:-https://dkapi.runxian.top}"
export VITE_API_TARGET="${VITE_API_TARGET:-https://api.dukanghaoke.com}"
pnpm approve-builds --all 2>/dev/null || true
pnpm install --frozen-lockfile 2>/dev/null || pnpm install
+19 -7
View File
@@ -30,13 +30,25 @@ HOOK_CONF="$DEPLOY_DIR/nginx-deploy-webhook.conf"
rm -f /etc/nginx/conf.d/dukang-deploy-webhook.conf
MARKER="include $HOOK_CONF;"
for conf in /etc/nginx/conf.d/dukang-runxian.conf /etc/nginx/conf.d/dukang-runxian-ssl.conf; do
if [[ -f "$conf" ]] && grep -q 'server_name dkapi.runxian.top' "$conf"; then
# 清理旧错误 include
sed -i '\|include /etc/nginx/conf.d/dukang-deploy-webhook.conf;|d' "$conf"
for conf in \
/etc/nginx/sites-available/dukang \
/etc/nginx/conf.d/dukang-runxian.conf \
/etc/nginx/conf.d/dukang-runxian-ssl.conf
do
if [[ ! -f "$conf" ]]; then
continue
fi
# 清理旧错误 include
sed -i '\|include /etc/nginx/conf.d/dukang-deploy-webhook.conf;|d' "$conf"
if grep -q 'server_name api.dukanghaoke.com' "$conf"; then
if ! grep -qF "$MARKER" "$conf"; then
sed -i "/server_name api.dukanghaoke.com;/a\\ $MARKER" "$conf"
echo " 已 patch $conf (api.dukanghaoke.com)"
fi
elif grep -q 'server_name dkapi.runxian.top' "$conf"; then
if ! grep -qF "$MARKER" "$conf"; then
sed -i "/server_name dkapi.runxian.top;/a\\ $MARKER" "$conf"
echo " 已 patch $conf"
echo " 已 patch $conf (dkapi.runxian.top)"
fi
fi
done
@@ -62,14 +74,14 @@ SECRET="$(grep DEPLOY_WEBHOOK_SECRET "$ENV_FILE" | cut -d= -f2- | tr -d '\"')"
echo ""
echo "=========================================="
echo " Webhook 已就绪"
echo " URL: https://dkapi.runxian.top/hooks/deploy"
echo " URL: https://api.dukanghaoke.com/hooks/deploy"
echo " Secret: $SECRET"
echo " Branch: dev (refs/heads/dev)"
echo " Log: $LOG_DIR/deploy.log"
echo "=========================================="
echo ""
echo "CodeUp 配置:仓库 → 设置 → Webhooks → 添加"
echo " URL: https://dkapi.runxian.top/hooks/deploy"
echo " URL: https://api.dukanghaoke.com/hooks/deploy"
echo " Secret Token: (与上方 Secret 相同)"
echo " 触发事件: Push events"
echo " 分支过滤: dev"