# Syncthing — 部署教程（Docker Compose + 反向代理）

> 去中心化的多设备文件同步工具，无需中心服务器。

- 页面: https://deploy.cc/zh/apps/syncthing
- 分类: 网盘与文件
- 服务器配置: 官方未给出明确最低配置；本站通用建议：1 核 / 1 GB 内存起（非官方数据）
- 端口: 8384 (Web 管理界面)；22000 (同步（TCP/UDP）)；21027/udp (局域网发现)
- CPU 架构: 镜像提供 amd64 / arm64（按镜像 manifest 核对于 2026-11-14）
- 一键安装: `curl -fsSL https://deploy.cc/i/syncthing.sh -o syncthing.sh && sudo bash syncthing.sh --domain example.com` (sha256 f8a3a419d6846a4f67249bb6b924fffe12c619fa2b2b2f946c62d4a3225f6d65)
- 官方仓库: https://github.com/syncthing/syncthing
- 官方文档: https://docs.syncthing.net/
- 部署来源: https://github.com/syncthing/syncthing/blob/main/README-Docker.md
- 核验程度: 配置已校验（compose config 通过、镜像存在，未启动）
- 最后核对: 2026-11-13

## docker-compose.yml (/opt/syncthing)

```yaml
# Syncthing — docker-compose.yml (deploy.cc)
# 官方来源 / Official source: https://github.com/syncthing/syncthing/blob/main/README-Docker.md
# 核对日期 / Checked: 2026-11-13
# 改动: 同步目录 /wherever/st-sync 改为 ./sync
services:
  syncthing:
    image: syncthing/syncthing:latest
    hostname: my-syncthing
    environment:
      - PUID=1000
      - PGID=1000
      - STGUIADDRESS=
    volumes:
      - ./sync:/var/syncthing
    network_mode: host
    restart: unless-stopped
    healthcheck:
      test: curl -fkLsS -m 2 127.0.0.1:8384/rest/noauth/health | grep -o --color=never OK || exit 1
      interval: 1m
      timeout: 10s
      retries: 3
```

## .env

```bash
# Syncthing — deploy.cc .env 模板 / template
# __GEN_*__ 由一键脚本替换为随机值；手动部署请自己改掉。
TZ=Asia/Shanghai
```

## 注意

- 官方示例使用 host 网络。首次进入 Web 界面后请立即设置 GUI 用户名和密码。
- 通过域名反代访问 GUI 时，Syncthing 会检查 Host 头，需要在设置里配置或按官方文档处理。

## Nginx

```nginx
# Syncthing 反向代理 / reverse proxy — generated by deploy.cc
# 把 example.com 换成你的域名，证书路径按实际修改（certbot / acme.sh 签发）。
# Replace example.com and the certificate paths. More options: https://nginx.cc/zh/gen
# 放到 /etc/nginx/conf.d/<name>.conf，然后 nginx -t && systemctl reload nginx

server {
    listen 80;
    listen [::]:80;
    server_name example.com;

    location /.well-known/acme-challenge/ {
        root /var/www/html;
    }

    location / {
        return 301 https://$host$request_uri;
    }
}

server {
    listen 443 ssl;
    listen [::]:443 ssl;
    http2 on;  # nginx < 1.25.1: 删除此行，改为 listen 443 ssl http2;
    server_name example.com;

    ssl_certificate     /etc/letsencrypt/live/example.com/fullchain.pem;
    ssl_certificate_key /etc/letsencrypt/live/example.com/privkey.pem;
    ssl_protocols TLSv1.2 TLSv1.3;

    client_max_body_size 0;

    location / {
        proxy_pass http://127.0.0.1:8384;
        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_read_timeout 300s;
    }
}
```

## Caddy

```caddy
# Syncthing — Caddyfile (deploy.cc). Caddy 会自动申请 HTTPS 证书 / automatic HTTPS
example.com {
    reverse_proxy 127.0.0.1:8384
}
```

## 更新

```bash
cd /opt/syncthing && docker compose pull && docker compose up -d && docker image prune -f
```

## 备份

```bash
cd /opt/syncthing && docker compose stop && tar czf /root/syncthing-$(date +%F).tar.gz -C /opt syncthing && docker compose start
```

## FAQ

### Syncthing 是什么？

去中心化的多设备文件同步工具，无需中心服务器。官方仓库：https://github.com/syncthing/syncthing

### 部署 Syncthing 需要什么配置的服务器？

官方未给出明确最低配置；本站通用建议：1 核 / 1 GB 内存起（非官方数据）

### Syncthing 使用哪些端口？

8384 (Web 管理界面)；22000 (同步（TCP/UDP）)；21027/udp (局域网发现)。Web 端口只监听 127.0.0.1，通过 Nginx 或 Caddy 反向代理对外提供 HTTPS。

### Syncthing 能在 ARM（arm64）服务器上运行吗？

可以。本页 compose 用到的镜像（syncthing/syncthing:latest）都提供 arm64 版本（按镜像 manifest 核对于 2026-11-14）。

### 怎样一键安装 Syncthing？

在 Linux 服务器上以 root 运行：curl -fsSL https://deploy.cc/i/syncthing.sh -o syncthing.sh && sudo bash syncthing.sh --domain example.com。脚本没有 Docker 时会用官方 get.docker.com 安装，把文件写到 /opt/syncthing，生成随机密码，然后 docker compose up -d；端口被占用或目录已存在时会停止，不覆盖。

### Syncthing 的数据存在哪里？怎么备份？

所有数据和 .env 都在 /opt/syncthing 目录（绑定挂载）。备份：cd /opt/syncthing && docker compose stop && tar czf /root/syncthing-$(date +%F).tar.gz -C /opt syncthing && docker compose start

### 怎样更新 Syncthing？

cd /opt/syncthing && docker compose pull && docker compose up -d && docker image prune -f。大版本升级前先备份并阅读官方更新说明。

### 这里的 docker-compose 和官方示例有什么不同？

来源：https://github.com/syncthing/syncthing/blob/main/README-Docker.md。改动：同步目录 /wherever/st-sync 改为 ./sync。

---
deploy.cc（非官方站点，商标归各自所有者）· v0.2.2
