Why Self-Host?
1. Choosing the Right Infrastructure
- Cheap VPS (Hetzner, DigitalOcean, Linode): The best starting point for personal projects. For $4 to $6 a month, you get a dedicated public IP, solid uptime, and a clean Linux OS (Ubuntu Server or Debian).
- Home Lab (Raspberry Pi, mini PC, old laptop): Good for media servers, local database backups, and private tools. It runs for free (aside from power costs) and has large storage potential, though you need to manage dynamic DNS and home router port forwarding safely.
- Hyperscalers (AWS, Azure, GCP): Overkill for basic hosting. Use them only if you specifically want to learn their services, like AWS S3 or GCP's serverless tools. Otherwise, the pricing models make it easy to rack up unexpected bills.
2. The Deployment Backbone: Docker & Compose
3. Basic Security Hardening
- SSH Keys Only: Disable password-based authentication. Edit /etc/ssh/sshd_config, set PasswordAuthentication no, and add your public SSH key to ~/.ssh/authorized_keys.
- Set Up a Firewall: Limit incoming traffic. If you use Ubuntu, ufw makes this straightforward:
- Automate SSL Certificates: Use Certbot (Let's Encrypt) to generate free HTTPS certificates. Nginx or Caddy can handle automatic renewals.
- Install Fail2ban: This service monitors log files for repeated failed login attempts and temporarily bans those IP addresses at the firewall level.
4. Monitoring & Backup Strategy
- Status Checks: For a simple setup, a cron job that pings your site and sends a Telegram or Discord webhook on a non-200 response works fine.
- Log Management: Docker writes logs to JSON files on the host. Set log rotation limits in /etc/docker/daemon.json to prevent storage from filling with debug logs:
- Backups: Code lives in Git, but databases and user uploads need active backup plans. A nightly cron job that runs pg_dump (for PostgreSQL) or copies raw mount directories, compresses them, and uploads them to a cloud bucket (Backblaze B2 or AWS S3) is the baseline.