Skip to content

部署指南

本指南介绍如何将 VitePress 官网部署到服务器。

自动部署

修改官网内容后,运行:

bash
npm run deploy

该命令会执行:

  1. vitepress build docs 构建文档
  2. 通过 SCP 上传到服务器
  3. 重载 Nginx

服务器信息:

  • IP: 106.53.10.172
  • Web 目录: /www/wwwroot/gzmusic
  • SSH 密钥: 106.53.10.172_id_ed25519

手动部署

1. 构建

bash
cd gz-music-player
npm run docs:build

构建输出位于 docs/.vitepress/dist

2. 上传

使用 SCP:

bash
scp -r docs/.vitepress/dist/* root@106.53.10.172:/www/wwwroot/gzmusic/

或使用 rsync:

bash
rsync -avz --delete docs/.vitepress/dist/ root@106.53.10.172:/www/wwwroot/gzmusic/

3. 重载 Nginx

bash
ssh root@106.53.10.172 "nginx -s reload"

Nginx 配置

nginx
server {
    listen 80;
    server_name guazi.fun;
    return 301 https://$server_name$request_uri;
}

server {
    listen 443 ssl http2;
    server_name guazi.fun;

    root /www/wwwroot/gzmusic;
    index index.html;

    location / {
        try_files $uri $uri/ /index.html;
    }

    location ~* \.(js|css|png|jpg|jpeg|gif|ico|svg|woff|woff2|ttf|eot)$ {
        expires 1y;
        add_header Cache-Control "public, immutable";
    }

    gzip on;
    gzip_vary on;
    gzip_min_length 1000;
    gzip_proxied any;
    gzip_comp_level 6;
    gzip_types text/plain text/css text/xml text/javascript application/json application/javascript application/xml+rss application/atom+xml image/svg+xml;
}

常见问题

页面刷新 404

确保 Nginx 配置中包含 try_files $uri $uri/ /index.html;

静态资源路径错误

如果部署在子目录,需要在 docs/.vitepress/config.cjs 中设置 base

javascript
module.exports = {
  base: '/gz-music/'
}

HTTPS 证书错误

检查宝塔面板中的 SSL 证书配置,确保证书未过期。

基于 MIT 许可证发布