📦

Caddy

Web Servers & Containers

Modern webbserver med automatisk HTTPS och enkel konfiguration

Deployment Info

Spridning: 2-5 min
kategori: Web Servers & Containers
Stöd: 24/7

Share this guide

Overview

Caddy is a powerful, enterprise-ready web server with automatic HTTPS that makes serving websites remarkably simple. Unlike traditional web servers that require complex configuration files and manual SSL certificate management, Caddy automatically obtains and renews SSL/TLS certificates from Let's Encrypt, making HTTPS the default for all your sites with zero configuration.

Built in Go for exceptional performance and reliability, Caddy combines the ease of use of modern platforms with the power and flexibility needed for production deployments. The server uses a simple, intuitive Caddyfile configuration format that's human-readable and easy to maintain, eliminating the need to learn complex Apache or nginx syntax.

Caddy excels as a reverse proxy, load balancer, and API gateway, with built-in support for HTTP/2, HTTP/3 (QUIC), WebSocket, gRPC, and FastCGI. It can serve static files blazingly fast, act as a reverse proxy for your applications, automatically compress responses, and handle complex routing scenarios with ease. The server's modular architecture allows you to extend functionality through a rich ecosystem of plugins.

One of Caddy's standout features is its automatic HTTPS management. When you configure a site, Caddy automatically obtains a trusted certificate, serves it with optimal security settings, and manages renewal before expiration - all without any manual intervention. This makes securing websites trivial, even for those without deep knowledge of SSL/TLS.

Caddy includes powerful features like on-demand TLS certificate issuance (perfect for SaaS platforms with custom domains), graceful configuration reloads with zero downtime, health checks, circuit breakers, rate limiting, and request/response manipulation. The server can also act as a file server with automatic directory browsing, markdown rendering, and template processing.

For developers, Caddy offers a JSON API for dynamic configuration changes, making it perfect for containerized and orchestrated environments. Whether you're running a simple static site, a complex microservices architecture, or anything in between, Caddy provides the tools you need with a delightful developer experience.

Key Features

Automatic HTTPS

Automatic SSL/TLS certificate obtainment and renewal from Let's Encrypt with zero configuration

Simple Configuration

Human-readable Caddyfile format that's easy to write and maintain, or JSON for programmatic control

HTTP/2 & HTTP/3 Support

Native support for HTTP/2, HTTP/3 (QUIC), WebSocket, gRPC, and other modern protocols

Reverse Proxy & Load Balancing

Advanced reverse proxy with load balancing, health checks, circuit breakers, and active/passive failover

On-Demand TLS

Issue certificates on-demand for SaaS platforms with thousands of custom domains

Zero-Downtime Reloads

Gracefully reload configuration without dropping connections or causing downtime

Användningsfall

• **Static Website Hosting**: Serve static sites with automatic HTTPS and HTTP/2 push
• **Reverse Proxy**: Proxy requests to backend services with automatic HTTPS and load balancing
• **API Gateway**: Route and load balance API requests with rate limiting and authentication
• **SaaS Platforms**: On-demand TLS for thousands of customer domains
• **Microservices**: Service mesh, service discovery, and inter-service communication
• **File Server**: Serve files with directory browsing, templates, and markdown rendering
• **Development Server**: Local development with automatic HTTPS (trust local CA)

Installation Guide

**Installation on Ubuntu:**
```bash
# Install Caddy from official repository
sudo apt install -y debian-keyring debian-archive-keyring apt-transport-https curl
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

# Or download binary directly
curl -o caddy 'https://caddyserver.com/api/download?os=linux&arch=amd64'
chmod +x caddy
sudo mv caddy /usr/local/bin/

# Verify installation
caddy version
```

**Quick Start - Static Site:**
```bash
# Create Caddyfile
cat > Caddyfile <<EOF
example.com {
root * /var/www/html
file_server
}
EOF

# Start Caddy
sudo caddy start

# Or run in foreground
sudo caddy run
```

**Reverse Proxy Example:**
```bash
cat > Caddyfile <<EOF
api.example.com {
reverse_proxy localhost:8080
}
EOF

sudo caddy run
```

Configuration Tips

**Basic Configuration (Caddyfile):**
```
# Simple static site with automatic HTTPS
example.com {
root * /var/www/html
file_server
encode gzip
}

# Reverse proxy to backend
api.example.com {
reverse_proxy localhost:3000
}

# Multiple backends with load balancing
app.example.com {
reverse_proxy localhost:8080 localhost:8081 localhost:8082 {
lb_policy round_robin
health_check /health
}
}

# SPA with fallback
spa.example.com {
root * /var/www/spa
try_files {path} /index.html
file_server
}
```

**Advanced Features:**
- **Rate Limiting**: Limit requests per client
- **Authentication**: Basic auth, JWT validation
- **Compression**: Automatic gzip/brotli
- **Templates**: Server-side includes and rendering
- **Request/Response Manipulation**: Headers, rewrites
- **Metrics**: Prometheus-compatible metrics
- **Logging**: Structured JSON logging

**Performance Tips:**
- Enable HTTP/2 push for critical resources
- Use `encode gzip zstd` for better compression
- Configure `file_server {precompressed gzip br}` for pre-compressed assets
- Use `header` directive to set caching headers

Betygsätt den här artikeln

-
Loading...

Redo att driftsätta din applikation? ?

Get started in minutes with our simple VPS deployment process

Inget kreditkort krävs för registrering • Implementeras på 2–5 minuter