Caddy Webserver Automatisches SSL
Caddy: Webserver mit Auto-HTTPS
Caddy ist ein moderner Webserver mit automatischer HTTPS-Konfiguration. Let's Encrypt Zertifikate werden automatisch angefordert und erneuert - ohne manuelle Einrichtung.
Installation
# Ubuntu/Debian
sudo apt install -y debian-keyring debian-archive-keyring apt-transport-https
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 caddy -y
# Status
sudo systemctl status caddy
Einfache Konfiguration
sudo nano /etc/caddy/Caddyfile
# Statische Website
example.com {
root * /var/www/example.com
file_server
}
sudo systemctl reload caddy
Das war's! Caddy holt automatisch ein SSL-Zertifikat und konfiguriert HTTPS.
PHP-Website
example.com {
root * /var/www/example.com
php_fastcgi unix//run/php/php8.3-fpm.sock
file_server
}
Reverse Proxy
# Node.js App
app.example.com {
reverse_proxy localhost:3000
}
# Mit Load Balancing
api.example.com {
reverse_proxy localhost:3001 localhost:3002 localhost:3003
}
# WebSocket
ws.example.com {
reverse_proxy localhost:8080
}
Mehrere Domains
example.com {
root * /var/www/example.com
file_server
}
blog.example.com {
root * /var/www/blog
php_fastcgi unix//run/php/php8.3-fpm.sock
file_server
}
app.example.com {
reverse_proxy localhost:3000
}
Erweiterte Optionen
example.com {
root * /var/www/example.com
# Komprimierung
encode gzip zstd
# Logging
log {
output file /var/log/caddy/access.log
}
# Headers
header {
X-Frame-Options "SAMEORIGIN"
X-Content-Type-Options "nosniff"
-Server
}
# Redirects
redir /old-page /new-page permanent
# Rewrites
rewrite /api/* /index.php?{path}
file_server
}
HTTP Basic Auth
# Passwort-Hash generieren
caddy hash-password
example.com {
basicauth /admin/* {
admin $2a$14$... # Hash von oben
}
file_server
}
Wildcards
# Wildcard-Zertifikat (DNS-Challenge nötig)
*.example.com {
tls {
dns cloudflare {env.CF_API_TOKEN}
}
reverse_proxy localhost:3000
}
Lokale Entwicklung
# HTTP ohne HTTPS
:8080 {
root * /var/www/html
file_server
}
# Oder
localhost {
root * /var/www/html
file_server
}
Nützliche Befehle
# Konfiguration prüfen
caddy validate --config /etc/caddy/Caddyfile
# Neu laden
sudo systemctl reload caddy
# Formatieren
caddy fmt --overwrite /etc/caddy/Caddyfile
# Manuell starten
caddy run --config /etc/caddy/Caddyfile
Caddy vs. Nginx
| Aspekt | Caddy | Nginx |
|---|---|---|
| HTTPS | Automatisch | Manuell (Certbot) |
| Syntax | Sehr einfach | Komplexer |
| Performance | Sehr gut | Exzellent |
| Verbreitung | Wachsend | Standard |
Weitere Hilfe
- 📖 Caddy Dokumentation
- 📧 E-Mail: support@enjyn.de