Commit 424c9f87 authored by tao355667's avatar tao355667

chore: adapt deployment for new server

parent 22513c25
Pipeline #467 passed with stage
......@@ -13,10 +13,10 @@ variables:
DEPLOY_LOCK: "/root/qiyouxue/shared/deploy.lock"
APP_NAME: "qiyouxue"
SITE_URL: "http://127.0.0.1:8793/"
PM2_BIN: "/usr/bin/pm2"
PUBLIC_URL: "http://127.0.0.1/"
PM2_BIN: "/root/.nvm/versions/node/v20.20.2/bin/pm2"
PM2_HOME_DIR: "/root/.pm2"
PM2_USE_SUDO: "1"
PUBLIC_HOST: "qiyouxueedu.com"
PM2_USE_SUDO: "0"
stages:
- deploy
......@@ -45,6 +45,7 @@ deploy:
/*) ;;
*) echo "PM2_HOME_DIR 必须是绝对路径" >&2; exit 2 ;;
esac
export PATH="$(dirname "$PM2_BIN"):$PATH"
if [ "$CURRENT_DIR" != "$DEPLOY_ROOT/current" ] || [ "$SHARED_DIR" != "$DEPLOY_ROOT/shared" ]; then
echo "current 或 shared 目录不属于部署根目录" >&2
exit 2
......@@ -176,11 +177,12 @@ deploy:
test -f "$CURRENT_DIR/deploy/nginx/qiyouxue.conf" || (echo "缺少 Nginx 配置" >&2 && exit 2)
sudo -n /usr/bin/install -o root -g root -m 0644 "$CURRENT_DIR/deploy/nginx/qiyouxue.conf" /etc/nginx/conf.d/qiyouxue.conf
sudo -n /usr/sbin/nginx -t
sudo -n /usr/bin/systemctl reload nginx
curl --fail --silent --show-error --max-time 5 \
--noproxy "*" \
--resolve "$PUBLIC_HOST:443:127.0.0.1" \
"https://$PUBLIC_HOST/" >/dev/null
if sudo -n /usr/bin/systemctl is-active --quiet nginx; then
sudo -n /usr/bin/systemctl reload nginx
else
sudo -n /usr/bin/systemctl enable --now nginx
fi
curl --fail --silent --show-error --max-time 5 "$PUBLIC_URL" >/dev/null
echo "[deploy] 部署完成:$CURRENT_DIR"
echo "[deploy] 旧 releases 目录未被读取或清理;确认无用后请人工删除"
......@@ -80,6 +80,6 @@ Word 导入示例字段:
- PM2 应用名:`qiyouxue`
- 服务端口:`8793`
- Nginx 配置:`/etc/nginx/conf.d/qiyouxue.conf`
- 公网域名:`qiyouxueedu.com`
- 临时公网入口:服务器 IP 的 HTTP 80 端口
Runner 需具备安装固定 Nginx 配置、执行 `nginx -t` 与 reload 的最小 sudo 权限。生产密钥、上传文件、CMS 数据、构建锁与内容写锁必须位于 `shared/`。建议内容写锁放在 `CMS_DATA_DIR` 内,确保所有 Node 进程看到同一锁文件。
......@@ -50,7 +50,7 @@ npm start
- Nginx 配置:`deploy/nginx/qiyouxue.conf`
- 生产端口:`8793`
- 站点域名:`qiyouxueedu.com`
- 临时公网入口:服务器 IP 的 HTTP 80 端口
- 服务器目录:`/root/qiyouxue/current``/root/qiyouxue/shared`
生产部署前需在 `/root/qiyouxue/shared/.env` 配置独立的 `CMS_PASSWORD``CMS_SECRET``CMS_API_KEY``CMS_DATA_DIR``CMS_BUILD_LOCK``CMS_CONTENT_LOCK`。构建锁只保护部署时的 `dist/` 替换;内容锁只保护 CMS 的 Markdown 与分类写入,两者不要共用路径。
# 启优学官网:HTTP 统一跳转至 HTTPS 主域名
# 启优学官网:域名和 HTTPS 启用前,暂时通过 80 端口提供服务
server {
listen 80;
server_name qiyouxueedu.com www.qiyouxueedu.com;
return 301 https://qiyouxueedu.com$request_uri;
}
server {
listen 443 ssl http2;
server_name www.qiyouxueedu.com;
ssl_certificate /etc/nginx/certs/qiyouxueedu.com.fullchain.pem;
ssl_certificate_key /etc/nginx/certs/qiyouxueedu.com.certkey.pem;
ssl_protocols TLSv1.2 TLSv1.3;
return 301 https://qiyouxueedu.com$request_uri;
}
server {
listen 443 ssl http2;
server_name qiyouxueedu.com;
ssl_certificate /etc/nginx/certs/qiyouxueedu.com.fullchain.pem;
ssl_certificate_key /etc/nginx/certs/qiyouxueedu.com.certkey.pem;
ssl_protocols TLSv1.2 TLSv1.3;
ssl_session_cache shared:QIYOUXUE:10m;
ssl_session_timeout 1d;
ssl_session_tickets off;
listen 80 default_server;
listen [::]:80 default_server;
server_name "";
client_max_body_size 28m;
location / {
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment