Syncthing is an open-source, peer-to-peer file synchronization application designed to replace proprietary sync and cloud services. By self-hosting Syncthing, you retain complete control over your data while ensuring secure and efficient file synchronization across devices. In this guide, weβll cover installation, reverse proxy configuration, logging, backups, updates, and advanced features of Syncthing to help you deploy and manage it effectively in your environment.
Installing Syncthing
π¦ Docker/Docker Compose Setup
To deploy Syncthing using Docker, create a docker-compose.yml
file to define the service and its settings. This setup enables easy container management and ensures persistent data storage.
version: '3.8'
services:
syncthing:
image: syncthing/syncthing:latest
container_name: syncthing
ports:
- "8384:8384" # Web UI
- "22000:22000/tcp" # Sync Protocol
- "21027:21027/udp" # Local Discovery
volumes:
- ./config:/var/syncthing/config
- ./sync:/var/syncthing/sync
environment:
- PUID=1000
- PGID=1000
restart: unless-stopped
Deploy Syncthing with the following commands:
docker-compose up -d
docker ps # Verify the container is running
π Manual Installation
For a manual installation on a Linux-based server, use the official Syncthing binaries:
sudo apt update && sudo apt install -y curl tar
## Download Syncthing
curl -s https://syncthing.net/release-key.txt | sudo gpg --dearmor -o /usr/share/keyrings/syncthing-archive-keyring.gpg
echo "deb [signed-by=/usr/share/keyrings/syncthing-archive-keyring.gpg] https://apt.syncthing.net/ syncthing stable" | sudo tee /etc/apt/sources.list.d/syncthing.list
## Install Syncthing
sudo apt update && sudo apt install -y syncthing
## Start Syncthing
syncthing
Configuring Nginx as a Reverse Proxy
π Nginx Configuration
Use Nginx to route external traffic to Syncthing for better access control and SSL termination. Create a new configuration file in /etc/nginx/sites-available/syncthing
:
server {
listen 80;
server_name yourdomain.com;
location / {
proxy_pass http://localhost:8384;
proxy_set_header Host $host;
proxy_set_header X-Real-IP $remote_addr;
proxy_set_header X-Forwarded-For $proxy_add_x_forwarded_for;
}
}
Enable the site and reload Nginx:
sudo ln -s /etc/nginx/sites-available/syncthing /etc/nginx/sites-enabled/
sudo nginx -t
sudo systemctl reload nginx
π SSL/TLS Setup
Use Let's Encrypt to secure your Syncthing deployment:
sudo apt install -y certbot python3-certbot-nginx
sudo certbot --nginx -d yourdomain.com
sudo systemctl reload nginx
π οΈ Testing and Reloading Nginx
Verify the Nginx configuration and ensure Syncthing is accessible via https://yourdomain.com
:
sudo nginx -t
sudo systemctl reload nginx
Logging and Debugging Syncthing
ποΈ Enabling Debug Logs
Enable debug-level logging in Syncthingβs configuration file. Locate the config.xml
(default path: ~/.config/syncthing/config.xml
) and modify the <logLevel>
parameter:
<logLevel>debug</logLevel>
π Viewing Logs
Access logs using Docker or directly from the file system:
## Docker logs
docker logs -f syncthing
## Manual Installation
journalctl -u syncthing -f
π οΈ Troubleshooting Common Issues
Check logs for common issues, such as connectivity errors or permission problems. For example:
grep "error" ~/.config/syncthing/syncthing.log
π€ Exporting Logs
Forward logs to an external ELK Stack for advanced analysis by using Filebeat:
sudo apt install filebeat
sudo nano /etc/filebeat/filebeat.yml
## Configure Syncthing log path and output destination
Backup and Restore
ποΈ File-Based Backups
Backup Syncthingβs configuration and synced files:
tar -czvf syncthing-backup.tar.gz ~/.config/syncthing ~/sync
π Database Backups
Syncthing stores metadata in index-v0.14.db
. Backup it directly:
tar -czvf syncthing-db-backup.tar.gz ~/.config/syncthing/index-v0.14.db
π Automated Backup Scripts
Set up a cron job to automate backups:
crontab -e
## Add the following line for daily backups at 2 AM
0 2 * * * tar -czvf ~/syncthing-backup-$(date +\%F).tar.gz ~/.config/syncthing ~/sync
Updating and Upgrading Syncthing
β¬οΈ Updating Docker Images
Pull and redeploy the latest Syncthing Docker image:
docker-compose pull
docker-compose down
docker-compose up -d
π οΈ Manual Updates
Manually update Syncthing and restart:
sudo apt update && sudo apt install --only-upgrade syncthing
sudo systemctl restart syncthing
π Checking for Updates
Check for updates from the Syncthing Web UI under Actions > About or run:
syncthing --version
Leveraging Syncthingβs Unique Features
π§ Enabling APIs
Syncthing provides a REST API for automation and integrations. Enable it in config.xml
:
<gui enabled="true" tls="false">
<address>0.0.0.0:8384</address>
<apikey>your-api-key</apikey>
</gui>
Test the API with curl
:
curl -X GET -H "X-API-Key: your-api-key" http://localhost:8384/rest/system/version
π Advanced Configurations
Enhance Syncthingβs functionality by enabling advanced options, such as introducing folder-specific settings or tweaking bandwidth usage:
syncthing -option=folder -option=value
Wrapping Up
This guide provided an end-to-end walkthrough of deploying, configuring, and managing Syncthing. Whether you want to synchronize files securely, leverage APIs, or automate backups, Syncthing offers unparalleled flexibility for self-hosting. Start implementing the steps outlined here to unlock the full potential of Syncthing for your projects.