--- name: self-hosted-website description: Self-host a static website with automatic HTTPS using Caddy and Let's Encrypt. Use when agents need full autonomy over their web presence without relying on third-party hosting platforms. --- # Self-Hosted Website with Caddy Host your own static website with automatic HTTPS certificates—no manual SSL management, no platform dependencies, fully autonomous. ## Overview This skill provides: - Self-hosted web server (Caddy) - Automatic HTTPS via Let's Encrypt - DNS configuration via API - Zero manual certificate management - Full autonomy from third-party hosting platforms ## Why Self-Host? | Aspect | Platform Hosting | Self-Hosted | |--------|-----------------|-------------| | **SSL Cost** | Often paid add-on | Free (Let's Encrypt) | | **Control** | Platform TOS limited | Full control | | **Privacy** | Subject to platform policies | Your infrastructure | | **Customization** | Platform constraints | Unlimited | | **Autonomy** | Account can be banned | Infrastructure is yours | ## Prerequisites - VPS with public IP (see `lnvps` skill) - Domain name (see `unhuman-domains` skill) - DNS management access - Ports 80/443 open ## Quick Start ### 1. Install Caddy ```bash # Add Caddy repository curl -1sLf 'https://dl.cloudsmith.io/public/caddy/stable/gpg.key' | sudo gpg --dearmor -o /usr/share/keyrings/caddy-stable-archive-keyring.gpg curl -1sLf 'https://dl.cloudsmith.io/public/caddy/stable/debian.deb.txt' | sudo tee /etc/apt/sources.list.d/caddy-stable.list # Install sudo apt update && sudo apt install -y caddy ``` ### 2. Configure Caddy Create `/etc/caddy/Caddyfile`: ``` yourdomain.com { root * /var/www/yourwebsite file_server encode gzip } www.yourdomain.com { redir https://yourdomain.com{uri} } ``` ### 3. Deploy Website ```bash # Create web root sudo mkdir -p /var/www/yourwebsite # Copy your files sudo cp index.html /var/www/yourwebsite/ sudo chown -R caddy:caddy /var/www/yourwebsite # Start Caddy sudo systemctl enable --now caddy ``` ### 4. Configure DNS Point your domain to your VPS IP: ```bash # Using unhuman.domains API curl -s -X PUT https://unhuman.domains/api/domains/yourdomain.com/nameservers \ -H "Authorization: Bearer YOUR_TOKEN" \ -H "Content-Type: application/json" \ -d '{"nameservers":["ns1.systemdns.com","ns2.systemdns.com","ns3.systemdns.com"]}' # Set A records curl -s -X PUT https://unhuman.domains/api/domains/yourdomain.com/dns \ -H "Authorization: Bearer YOUR_TOKEN" \ -H "Content-Type: application/json" \ -d '{ "records": [ {"type": "A", "subdomain": "@", "ip": "YOUR_VPS_IP", "ttl": 300}, {"type": "A", "subdomain": "www", "ip": "YOUR_VPS_IP", "ttl": 300} ] }' ``` ### 5. Automatic HTTPS Caddy automatically: 1. Detects the domain 2. Registers with Let's Encrypt 3. Completes HTTP-01 challenge 4. Obtains and installs certificate 5. Enables HTTPS redirect **No manual intervention required.** ## Verification ```bash # Check Caddy status sudo systemctl status caddy # Verify certificate curl -sI https://yourdomain.com # Check local certificate storage sudo ls -la /var/lib/caddy/.local/share/caddy/certificates/ ``` ## Caddyfile Examples ### Static Site (Default) ``` example.com { root * /var/www/example file_server encode gzip } ``` ### With SPA (Single Page App) ``` example.com { root * /var/www/example file_server { index index.html } try_files {path} {path}/ /index.html # React/Vue routing } ``` ### With Custom Headers ``` example.com { root * /var/www/example file_server header { X-Frame-Options "SAMEORIGIN" X-Content-Type-Options "nosniff" Referrer-Policy "strict-origin-when-cross-origin" } } ``` ### With Reverse Proxy (API) ``` example.com { root * /var/www/example file_server # API backend reverse_proxy /api localhost:3000 } ``` ## Automation Script ```bash #!/bin/bash # deploy.sh - Autonomous website deployment DOMAIN="${1:-yourdomain.com}" WEBROOT="/var/www/$DOMAIN" VPS_IP="$(curl -s ifconfig.me)" # Install Caddy if not present if ! command -v caddy &> /dev/null; then curl -1sLf 'https://dl.cloudsmith.io/public/caddy/stable/gpg.key' | sudo gpg --dearmor -o /usr/share/keyrings/caddy-stable-archive-keyring.gpg curl -1sLf 'https://dl.cloudsmith.io/public/caddy/stable/debian.deb.txt' | sudo tee /etc/apt/sources.list.d/caddy-stable.list sudo apt update && sudo apt install -y caddy fi # Create Caddyfile sudo tee /etc/caddy/Caddyfile > /dev/null <