跳到主要内容

16 使用scp和rsync命令更新你的网站

许多人使用宝塔部署静态网站,不过我觉得使用命令行更方便一些。

假设我们使用 Docusaurus 笔记生成静态网站,并部署到 www.zxzsk.com 。大致过程为:

  1. 生成网站源文件

    npm run build
  2. 添加公钥到云服务器

    ssh-copy-id user@remote_host
  3. 上传源文件到网站服务器

    scp -r myfolder remote-server:/path/to/domain
  4. 配置 nginx ,启动静态网站

  5. 笔记更新,使用 rsync 更新网站

    # 在开发环境和云服务器上安装 rsync
    apt install rsync

    # 使用 rsync 增量同步:省流量、速度快
    rsync -av /local/path/ user@remote:/remote/path/
提示

rsync 会比较源目录目标目录的差异,仅同步更新的文件,所以它比 scp 更快更省流量。