Skip to content
fokxPublic

About

partial-drop-in replacement for caddy in Rust

Topics

Resources

Stars

6 stars

Watchers

0 watching

Forks

Repository files navigation

Raddy

License: Apache 2.0 Rust: 2024 Edition Protocols: HTTP/1.1 · HTTP/2 · HTTP/3 Caddyfile Compatible

Raddy is a high-performance, memory-safe, and extensible web server and reverse proxy written in modern Rust. Built as a ground-up Rust implementation compatible with Caddy, Raddy combines the beloved developer experience and human-friendly syntax of the Caddyfile with the performance, predictable latency, and zero-cost abstractions of the Rust ecosystem (Tokio, Hyper, Quinn, Rustls, and Axum).

Note

Trademark & Disclaimer: "Caddy" is a trademark of its respective owner(s). Raddy is an independent open-source project and is neither affiliated with, endorsed by, nor sponsored by the Caddy project or its creators.

The name Raddy was chosen simply for brevity and convenience: the initial "R" highlights Rust, and the name is short and easy to type and remember as a modern, high-performance drop-in replacement for Caddy. Its use is strictly descriptive and not intended to imitate or infringe upon any trademarks.


Table of Contents


Why Raddy?

Caddy revolutionized web serving with human-friendly configuration and automatic HTTPS out of the box. Raddy takes those proven design patterns and reimagines them in Rust:

  • No Garbage Collection Pauses: Consistent, ultra-low tail latencies under heavy load.
  • Minimal Memory Footprint: Safe, compact resource usage suitable for resource-constrained edge nodes, containers, and high-density multi-tenant environments.
  • Native HTTP/3 (QUIC): True native QUIC streaming powered by Quinn and h3 with automatic Alt-Svc negotiation.
  • Caddyfile Syntax Compatibility: Seamless migration from existing Caddy setups with full support for snippets, imports, named matchers, and directives.
  • Atomic Hot-Reloading: Dynamic configuration updates via Admin API or file watching with zero dropped requests, powered by ArcSwap.

Key Features

🌐 Modern Protocol Engine

  • HTTP/1.1 & HTTP/2: Powered by Hyper and Tokio with full support for both cleartext (h2c) and TLS-negotiated ALPN connections.
  • Native HTTP/3 over QUIC: High-speed, UDP-based HTTP/3 using Quinn and h3, advertising Alt-Svc: h3=":443" automatically.
  • Graceful Shutdown: Zero dropped connections during restarts and reloads.

🔒 Automated TLS & Certificate Management

  • Zero-Config ACME: Automatic HTTPS with Let's Encrypt and ZeroSSL via instant-acme.
  • Challenge Solvers: Built-in automated TLS-ALPN-01, HTTP-01, and DNS-01 challenge handling.
  • DNS-01 ACME Provider Plugin (caddy-dns/cloudflare): Cloudflare DNS-01 challenge provider plugin (dns.providers.cloudflare) for automated certificate validation and wildcard domain support (*.example.com).
  • Internal PKI / Local CA: Automatic self-signed root and leaf certificate generation via rcgen for local development (tls internal).
  • Dynamic SNI Matching: Multi-domain routing with lazy certificate loading, background renewals, and public/private IP SAN support.

🔀 Reverse Proxy & Load Balancing

  • Load Balancing Algorithms: round_robin, least_conn, random, and ip_hash.
  • Health Checks: Active background HTTP probing (interval, timeout, path) and passive circuit-breaking on connection failures.
  • Bidirectional Streaming: Native WebSocket proxying and chunked HTTP streaming without buffering large bodies.
  • Header Manipulation: Inject, modify, or strip upstream and downstream headers (header_up, header_down).
  • Forward Proxy & CONNECT Tunneling: Built-in forward proxy with HTTP CONNECT tunneling for outbound proxying and traffic gatewaying.

🎛️ Layer 4 (TCP/UDP) Multiplexing & Stream Routing (caddy-l4)

  • Protocol Multiplexing: Serve multiple protocols (e.g. SSH, HTTP, TLS) on the exact same port without performance overhead.
  • Matchers: Inspect connections by TLS SNI, ALPN, HTTP methods, SSH banners, PROXY protocol (v1/v2), IP/CIDR ranges, WireGuard, QUIC, SOCKS4/SOCKS5, Postgres SSLRequest, or regex.
  • Handlers: Layer 4 reverse proxy with dynamic load balancing (round_robin, least_conn, random, ip_hash), active & passive health checks, PROXY protocol header injection, echo (RFC 862), close, and TLS termination.
  • Full UDP Support: Bidirectional datagram forwarding, stateful packet association, and idle timeouts.
  • Caddyfile & JSON Parity: Seamless configuration via layer4 block in global options or top-level, adapting to Caddy's apps.layer4 layout.

📁 Static File Serving

  • Zero-Copy Serving: Fast, non-blocking asynchronous file delivery.
  • Directory Browsing: Mobile-friendly HTML index generation with breadcrumbs and human-readable file sizes (file_server browse).
  • Single-Page Application (SPA) Support: Fallback rewrites and file resolution with try_files.
  • MIME Type Detection: Accurate MIME inference with mime_guess.

⚡ Directives & Middleware

  • cache: Distributed and in-memory HTTP cache with RFC 7234 & RFC 9111 compliance (caddyserver/cache-handler / Souin parity), Cache-Status headers, stale-while-revalidate, conditional revalidation (304 Not Modified), and key normalization.
  • encode: Streaming on-the-fly response compression supporting both Gzip and Zstandard (zstd).
  • templates: Dynamic server-side templating powered by MiniJinja with access to request headers, path, and variables.
  • basic_auth: Secure HTTP Basic Authentication backed by bcrypt password hashes.
  • forward_auth: Delegation of authentication checks to external services (Authelia, Authentik, etc.).
  • request_body limits: Enforcement of maximum payload sizes to guard against DoS attacks.
  • log: Structured JSON or console access logs with customizable fields, path/header redactions, log rotation, and automated gzip log file rolling.
  • rewrite, respond, redir, abort, error: Expressive routing rules and customizable status responses.

Architecture & Crates

Raddy is structured as a modular Cargo workspace:

raddy/
├── Cargo.toml                     # Workspace root manifest (package: raddy-server, bin: raddy)
├── Caddyfile                      # Sample configuration
├── src/                           # CLI binary entrypoint & commands
├── docs/                          # In-depth architectural & functional chapters
└── crates/
    ├── raddy-core/              # Core traits, Matcher/Handler interfaces, placeholders, AST
    ├── raddy-caddyfile/         # Lexer, recursive-descent parser, AST adapter, snippet/import expander
    ├── raddy-http/              # HTTP/1.1, HTTP/2, HTTP/3 servers, routing engine, middleware handlers
    ├── raddy-tls/               # Automated ACME client, local CA/PKI, SNI resolver, challenge solvers
    ├── raddy-proxy/             # Reverse proxy, load balancers, health checks, forward proxy & tunneling
    ├── raddy-l4/                # Layer 4 (TCP/UDP) transport engine, matchers, handlers, and stream routing
    └── raddy-admin/             # Axum REST Admin API (:2019) and atomic ArcSwap config state manager

Documentation Chapters

Comprehensive technical documentation and deep dives are organized into functional chapters in the docs/ directory:


Installation & Build

Prerequisites

  • Rust 1.85+ (Rust 2024 Edition support required)
  • cmake and a C/C++ compiler (for native crypto libraries like aws-lc-sys / ring)

Pre-compiled Standalone Binaries

Download pre-compiled standalone executable binaries directly from the GitHub Releases page:

  • Linux (x86_64): raddy-v*.*.*-x86_64-unknown-linux-gnu.tar.gz
  • Linux ARM64: raddy-v*.*.*-aarch64-unknown-linux-gnu.tar.gz
  • macOS Apple Silicon (M1/M2/M3/M4): raddy-v*.*.*-aarch64-apple-darwin.tar.gz
  • macOS Intel: raddy-v*.*.*-x86_64-apple-darwin.tar.gz
  • Windows (x86_64): raddy-v*.*.*-x86_64-pc-windows-msvc.zip

Extract the archive and move raddy to your system PATH (e.g. /usr/local/bin on Linux/macOS).

Build from Source

# Clone the repository
git clone https://github.com/fokx/raddy.git
cd raddy

# Build release binary
cargo build --release

# The compiled binary will be located at:
./target/release/raddy --version

Docker & Container Deployment

Pre-built multi-architecture container images (linux/amd64, linux/arm64) are published to GitHub Container Registry (GHCR) in two variants:

Image Tag Base Image User Best For Ports
ghcr.io/fokx/raddy:latest gcr.io/distroless/static-debian13:nonroot nonroot (65532) Standard production environments (Docker 20.10+ with port 80/443 mapping) 80, 443, 2019
ghcr.io/fokx/raddy:nonroot gcr.io/distroless/static-debian13:nonroot nonroot (65532) Hardened environments (Kubernetes, Podman, unprivileged rootless ports) 8080, 8443, 2019
# Pull standard image
docker pull ghcr.io/fokx/raddy:latest

# Or pull hardened distroless nonroot image
docker pull ghcr.io/fokx/raddy:nonroot

Quick Start with Docker

Run an instant container serving on HTTP (:80) and HTTPS (:443 with native QUIC/HTTP/3):

docker run -d \
  --name raddy \
  --init \
  -p 80:80 \
  -p 443:443 \
  -p 443:443/udp \
  -v $(pwd)/Caddyfile:/etc/caddy/Caddyfile:ro \
  -v raddy_data:/data \
  -v raddy_config:/config \
  ghcr.io/fokx/raddy:latest
Running the Hardened :nonroot Image

The ghcr.io/fokx/raddy:nonroot image runs strictly as unprivileged user nonroot (UID 65532). It listens on unprivileged ports 8080 (HTTP) and 8443 (HTTPS), requiring zero elevated Linux capabilities (CAP_NET_BIND_SERVICE) or host sysctl tweaks.

Map the host ports 80 and 443 to container ports 8080 and 8443:

docker run -d \
  --name raddy \
  --init \
  -p 80:8080 \
  -p 443:8443 \
  -p 443:8443/udp \
  -v $(pwd)/Caddyfile.nonroot:/etc/caddy/Caddyfile:ro \
  -v raddy_data:/data \
  -v raddy_config:/config \
  ghcr.io/fokx/raddy:nonroot

Docker Compose

Two ready-to-run compose stacks are provided:

  1. Standard Image (docker-compose.yml):

    docker compose up -d
  2. Hardened Non-Root Distroless Image (docker-compose-nonroot.yml):

    docker compose -f docker-compose-nonroot.yml up -d

Tip

Non-Root Custom Ports in Caddyfile: When using the :nonroot image with Caddyfile.nonroot, declare http_port and https_port in global options:

{
    http_port 8080
    https_port 8443
}

localhost {
    respond "Hello from non-root Raddy!" 200
}

Any site blocks defined without an explicit port (like localhost or example.com) will automatically use 8443 for HTTPS and 8080 for HTTP redirects without requiring root permissions.

Configuring via Environment Variables

Raddy supports comprehensive environment variable configuration:

  1. Server & Operational Variables:

    Variable Description Default
    RUST_LOG Tracing filter directive (e.g. info, debug, trace, warn) info
    RADDY_DEBUG Enable verbose debug logging for TLS, ACME, and HTTP handlers false
    RADDY_DATA_DIR Storage path for persistent TLS certificates and ACME accounts /data
    RADDY_ACME_EMAIL Default contact email used for ACME certificate registration None
    RADDY_ACME_STAGING Set to 1 or true to use Let's Encrypt staging environment (avoids rate limits) false
    CLOUDFLARE_API_TOKEN API token for automatic Cloudflare DNS-01 challenge solving (wildcards) None
  2. Caddyfile Dynamic Substitution: Any custom environment variable passed to the container can be interpolated directly in your Caddyfile using {env.VARIABLE_NAME} syntax:

    :80 {
        reverse_proxy {env.BACKEND_HOST:127.0.0.1}:{env.BACKEND_PORT:8080}
    }

    Pass variables via Docker CLI or Compose:

    docker run -d \
      -p 80:80 \
      -e BACKEND_HOST="api_service" \
      -e BACKEND_PORT="3000" \
      -v $(pwd)/Caddyfile:/etc/caddy/Caddyfile:ro \
      ghcr.io/fokx/raddy:latest

Configuring via Command Line & Subcommands

The Docker container sets ENTRYPOINT ["raddy"], allowing you to run any Raddy CLI command directly:

# 1. Instant static file server with directory browsing
docker run -d -p 8080:8080 -v $(pwd)/public:/srv:ro ghcr.io/fokx/raddy:latest \
  file-server --listen 0.0.0.0:8080 --root /srv --browse

# 2. Instant one-liner reverse proxy
docker run -d -p 80:80 ghcr.io/fokx/raddy:latest \
  reverse-proxy --from 0.0.0.0:80 --to backend-service:8080

# 3. Validate Caddyfile syntax without starting the server
docker run --rm -v $(pwd)/Caddyfile:/etc/caddy/Caddyfile:ro ghcr.io/fokx/raddy:latest \
  validate --config /etc/caddy/Caddyfile

# 4. Format a Caddyfile in place
docker run --rm -v $(pwd):/workspace -w /workspace ghcr.io/fokx/raddy:latest \
  fmt --overwrite Caddyfile

# 5. Adapt Caddyfile to Raddy JSON configuration
docker run --rm -v $(pwd)/Caddyfile:/etc/caddy/Caddyfile:ro ghcr.io/fokx/raddy:latest \
  adapt --config /etc/caddy/Caddyfile --pretty

# 6. Generate bcrypt password hash for basic_auth
docker run --rm ghcr.io/fokx/raddy:latest hash-password "my-secret-password"

Zero-Downtime Hot Reload in Docker

Reload configuration dynamically without dropping client connections or restarting the container:

docker exec -it raddy raddy reload --config /etc/caddy/Caddyfile

Quick Start

1. Instant Static File Server

Serve any directory immediately with optional directory browsing and access logging:

# Serve the current directory on port 8000 with directory browsing enabled
raddy file-server --listen 127.0.0.1:8000 --browse --access-log

2. Reverse Proxy with Caddyfile

Create a Caddyfile in your project directory:

:8080 {
    # Compress responses using gzip or zstd
    encode gzip zstd

    # Route /api/* requests to backend cluster with round-robin load balancing
    reverse_proxy /api/* 127.0.0.1:5001 127.0.0.1:5002 {
        lb_policy round_robin
        header_up Host {upstream_hostport}
        header_up X-Real-IP {remote_host}
    }

    # Serve static assets for all other paths
    root * /var/www/html
    file_server browse
}

Run Raddy in the foreground:

raddy run --config Caddyfile

3. Running as a Daemon

Start Raddy in the background:

# Start background process
raddy start --config Caddyfile

# Stop the running background process via Admin API
raddy stop

4. Zero-Downtime Hot Reload

Modify your Caddyfile and reload without dropping any client connections:

# Reload via Admin API
raddy reload --config Caddyfile

# Or run with auto-watch enabled to reload on file save automatically
raddy run --config Caddyfile --watch

Configuration Guide

Directives & Matchers

Raddy supports standard Caddy matchers:

  • Path matchers: /api/*, /static/
  • Named matchers: @custom { path /v1/*; method POST PUT; header X-Key * }
  • Placeholders: {path}, {host}, {method}, {remote_host}, {http.request.header.Authorization}, etc.

Directives are automatically reordered according to standard production priority: basic_auth → rewrite → encode → templates → reverse_proxy → file_server → respond.

Production Caddyfile Example

# Global Options Block
{
    email admin@example.com
    http_port 80
    https_port 443
}

# Reusable Snippet
(security_headers) {
    header {
        X-Content-Type-Options nosniff
        X-Frame-Options DENY
        Referrer-Policy strict-origin-when-cross-origin
        -Server
    }
}

example.com {
    import security_headers

    # Transparent compression
    encode gzip zstd

    # Health check endpoint
    handle /healthz {
        respond "OK" 200
    }

    # API Proxy with active health checks
    @api path /api/*
    reverse_proxy @api 10.0.0.1:8080 10.0.0.2:8080 {
        lb_policy least_conn
        health_interval 5s
        health_timeout 2s
        health_path /health
    }

    # Static Website
    root * /var/www/site
    file_server browse
}

# Internal Gateway with Local Self-Signed CA
internal.lan {
    tls internal
    respond "Hello from private network!" 200
}

Forward Proxy & HTTP CONNECT Tunneling

Raddy also includes forward proxy capabilities with HTTP CONNECT tunneling:

:8888 {
    forward_proxy {
        # Optional: Hide user IP from forwarded headers
        hide_ip
        # Optional: Chain through an upstream proxy
        # upstream http://upstream-proxy:3128
    }
}

Command Line Interface (CLI)

Usage: raddy <COMMAND>

Commands:
  run           Runs Raddy with the specified configuration in foreground
  start         Starts Raddy in the background (daemon mode)
  stop          Stops a running Raddy instance via Admin API
  reload        Sends a zero-downtime configuration reload request
  validate      Validates a Caddyfile or JSON configuration without running
  adapt         Adapts a Caddyfile to Raddy internal JSON configuration
  fmt           Formats or normalizes a Caddyfile to canonical syntax
  list-modules  Lists all registered modules, directives, and matchers
  environ       Prints runtime environment variables
  version       Prints detailed version information
  file-server   Instant zero-config static file server
  help          Print this message or the help of the given subcommand(s)

CLI Examples

# Validate config syntax
raddy validate --config Caddyfile

# Convert Caddyfile into JSON config
raddy adapt --config Caddyfile --pretty

# Format Caddyfile in place
raddy fmt --config Caddyfile --overwrite

# Inspect all registered modules and handlers
raddy list-modules --json

Admin API

Raddy exposes a RESTful Admin API (default: http://127.0.0.1:2019) for dynamic, programmatic management:

Method Endpoint Description
POST /load Load and apply a new JSON or Caddyfile configuration without downtime
GET /config/ Retrieve the active running JSON configuration
POST /stop Gracefully shut down the server and active listeners

Unix Domain Socket & Permission Hardening

When listening on a local TCP socket (127.0.0.1:2019), any unprivileged local process can access the Admin API to inspect or alter configuration, initiate reloads, or terminate the server.

You can switch the Admin API to a permissioned Unix domain socket to restrict access exclusively to authorized users or groups:

{
    # Listen on a Unix socket with optional octal file permissions (|0660 or |0600)
    admin unix//run/raddy/raddy-admin.sock|0660
}

localhost:8080 {
    respond "Hello from hardened Raddy!" 200
}

Or using block syntax:

{
    admin {
        listen unix//run/raddy/raddy-admin.sock|0660
    }
}

Admin API Usage Examples

# Query the active configuration (TCP)
curl http://127.0.0.1:2019/config/

# Query the active configuration (Unix socket)
curl --unix-socket /run/raddy/raddy-admin.sock http://localhost/config/

# Dynamically reload configuration
curl -X POST --unix-socket /run/raddy/raddy-admin.sock \
     -H "Content-Type: text/caddyfile" \
     --data-binary @Caddyfile \
     http://localhost/load

# Gracefully stop the server via CLI using the Unix socket
raddy stop --address unix//run/raddy/raddy-admin.sock

# Or reload via CLI (auto-detects socket from Caddyfile when -a is omitted)
raddy reload --config Caddyfile

Testing

Run the full automated test suite (including unit tests, CLI tests, log rolling tests, and integration tests):

cargo test

License

This project is licensed under the Apache License 2.0. See the LICENSE file for details.

About

partial-drop-in replacement for caddy in Rust

Topics

Resources

Stars

6 stars

Watchers

0 watching

Forks

Releases

Packages

Contributors

Languages