This specification is maintained by the AgentRules Working Group. Have enhancements or want to claim maintainership?Submit Specification →
devopsmedium PriorityID: caddy-edge-webserver

Caddy 2 Modern Edge Webserver & Automatic TLS Standard

Modern edge reverse proxy and TLS termination with Caddy 2. Leverages automatic ACME certificates, zero-downtime reloads, memory-safe Go architecture, and concise Caddyfile directives with HTTP/3 support.

Prohibited Anti-Pattern: AI writes bloated Apache configs or fragile manual certbot cron scripts that fail during certificate renewal.

Export Ready-to-Drop Configuration

Select format below to copy code or download file directly.

---
description: Caddy 2 Modern Edge Webserver & Automatic TLS Standard - Modern edge reverse proxy and TLS termination with Caddy 2. Leverages automatic ACME certificates, zero-downtime reloads, memory-safe Go architecture, and concise Caddyfile directives with HTTP/3 support.
globs: Caddyfile, **/caddy/**
alwaysApply: false
verified_by: "agentrules.org"
license: "CC-BY-4.0"
source: "https://agentrules.org/rules/caddy-edge-webserver"
---

# Caddy 2 Modern Edge Webserver & Automatic TLS Standard

> **Severity**: MEDIUM | **Category**: devops
> **Anti-Pattern Warning**: AI writes bloated Apache configs or fragile manual certbot cron scripts that fail during certificate renewal.

## System Constraints
You are a modern web infrastructure engineer. When configuring Caddy 2, use declarative Caddyfile syntax. Never write manual Certbot renewal cron jobs or complex OpenSSL scripts; Caddy automates ACME certificate issuance and renewal natively. Ensure upstream reverse proxy directives include health checks and streaming buffer headers.

## Strict Guidelines
- Rely on Caddy native automatic HTTPS; do NOT run external certbot or manual ACME cron scripts.
- Always configure security headers (Strict-Transport-Security, X-Content-Type-Options, X-Frame-Options) in the Caddyfile.
- Configure active upstream health checks in `reverse_proxy` for multi-backend load balancing.
- Enable modern HTTP/3 and zstd/gzip compression using Caddy encode directive.

## Bad vs Good Implementations
### Production Caddyfile with Automatic TLS & Security Headers vs Complex Nginx/Apache

#### Bad Antipattern (AI Common Hallucination)
> **Why it fails**: Manual certificate renewal scripts fail on OS upgrades or DNS changes, leading to expired SSL outages.
```caddyfile
# ANTI-PATTERN: Complex legacy Apache/Nginx configuration with manual certbot cron
<VirtualHost *:80>
  ServerName api.example.com
  Redirect permanent / https://api.example.com/
</VirtualHost>
# Requires manual certbot renew --quiet in crontab that frequently expires silently!
```

#### Production Standard (Correct)
> **Standard**: Caddy automatically provisions and renews Let's Encrypt / ZeroSSL TLS certificates without cron jobs, providing out-of-the-box HTTP/3.
```caddyfile
# PRODUCTION STANDARD: Clean, declarative Caddyfile (Automatic TLS + HTTP/3 + Headers)
api.example.com {
  # 1. Automatic compression
  encode zstd gzip

  # 2. Hardened security response headers
  header {
    Strict-Transport-Security "max-age=31536000; includeSubDomains; preload"
    X-Content-Type-Options "nosniff"
    X-Frame-Options "DENY"
    Referrer-Policy "strict-origin-when-cross-origin"
    -Server # Strips server banner to prevent reconnaissance
  }

  # 3. High-performance reverse proxy with active health checks
  reverse_proxy {
    to 127.0.0.1:8080 127.0.0.1:8081
    lb_policy round_robin
    health_uri /healthz
    health_interval 5s
    health_timeout 2s
  }
}
```

### Zero-Downtime Configuration Reload

#### Bad Antipattern (AI Common Hallucination)
> **Why it fails**: Killing the process terminates active TCP sockets and drops ongoing user downloads.
```bash
# ANTI-PATTERN: Hard killing process to apply config changes
killall caddy && caddy run # Drops existing active client connections!
```

#### Production Standard (Correct)
> **Standard**: Validates the new configuration in memory before hot-swapping sockets without dropping a single packet.
```bash
# PRODUCTION STANDARD: Atomic zero-downtime reload via Caddy admin API
caddy reload --config /etc/caddy/Caddyfile
```

Recommended MCP Servers (mcp-serverlist.com)

Equip agent with system tools to verify code for this stack.

Recommended Agent Skills (askills.dev)

Ready-to-use executable skill functions tailored to this stack.

Architectural Specification & Invariant Rationale

Architectural Invariant Design: Caddy 2 Modern Edge Webserver & Automatic TLS Standard

Caddy 2 Modern Edge Webserver & Automatic TLS Standard defines an industrial-grade behavioral standard for devops engineering. Modern edge reverse proxy and TLS termination with Caddy 2. Leverages automatic ACME certificates, zero-downtime reloads, memory-safe Go architecture, and concise Caddyfile directives with HTTP/3 support. Modern software architectures require strict adherence to deterministic patterns to guarantee high availability, maintainability, and zero security vulnerabilities.

Framework Paradigm Shift & Drift MechanicsLLMs are trained on millions of open-source repositories containing outdated code, legacy idioms, and unpatched antipatterns. When coding assistants generate implementations for this stack, they default to common statistical tokens: AI writes bloated Apache configs or fragile manual certbot cron scripts that fail during certificate renewal. Without an explicit system instruction file, developers spend hours debugging silent failures.
Failure Modes & Production Blast Radius

Hazard Analysis: What Breaks Without This Rule

The following failure modes have been cataloged from hundreds of hours of production code reviews where AI assistants produced non-compliant implementations:

Failure ModeAI Symptom (The Anti-Pattern)SeverityProduction Impact & Remedy
AI Hallucination & Deprecation DriftAI writes bloated Apache configs or fragile manual certbot cron scripts that fail during certificate renewal.High
Violating this industrial standard introduces regression bugs, security risks, and unexpected runtime failures in production.
Enforce explicit behavioral system directives across all AI coding assistants in your repository.
Silent Architecture InconsistencyAI assistants produce mixed paradigms across files, creating fragmented codebase conventions.Medium
Increases cognitive load during code reviews and leads to maintenance debt across engineering teams.
Pin project conventions in .cursor/rules, CLAUDE.md, and AGENTS.md so all team agents follow identical guardrails.
Architectural Directives in Detail

Step-by-Step Production Directives

Each rule constraint below is injected into the AI agent's system prompt to establish deterministic boundaries:

1

Rely on Caddy native automatic HTTPS

Rely on Caddy native automatic HTTPS; do NOT run external certbot or manual ACME cron scripts.

Rationale:AI models frequently generate unconstrained code here because statistical language distributions lack project-specific architectural context. Mandating this directive ensures that generated code adheres to verified industrial production requirements.
Enforcement:Integrated into the Agent Pack rule file. When Cursor, Claude Code, or Codex processes this prompt, it applies this constraint before emitting syntax.
2

Always configure security headers (Strict-Transport-Security, X-Content-Type-Options, X-Frame-Options) in the Caddyfile.

Always configure security headers (Strict-Transport-Security, X-Content-Type-Options, X-Frame-Options) in the Caddyfile.

Rationale:AI models frequently generate unconstrained code here because statistical language distributions lack project-specific architectural context. Mandating this directive ensures that generated code adheres to verified industrial production requirements.
Enforcement:Integrated into the Agent Pack rule file. When Cursor, Claude Code, or Codex processes this prompt, it applies this constraint before emitting syntax.
3

Configure active upstream health checks in `reverse_proxy` for multi-backend load balancing.

Configure active upstream health checks in `reverse_proxy` for multi-backend load balancing.

Rationale:AI models frequently generate unconstrained code here because statistical language distributions lack project-specific architectural context. Mandating this directive ensures that generated code adheres to verified industrial production requirements.
Enforcement:Integrated into the Agent Pack rule file. When Cursor, Claude Code, or Codex processes this prompt, it applies this constraint before emitting syntax.
4

Enable modern HTTP/3 and zstd/gzip compression using Caddy encode directive.

Enable modern HTTP/3 and zstd/gzip compression using Caddy encode directive.

Rationale:AI models frequently generate unconstrained code here because statistical language distributions lack project-specific architectural context. Mandating this directive ensures that generated code adheres to verified industrial production requirements.
Enforcement:Integrated into the Agent Pack rule file. When Cursor, Claude Code, or Codex processes this prompt, it applies this constraint before emitting syntax.
Technical Questions & Answers

Frequently Asked Technical Questions

Common questions developers face when configuring AI coding assistants for this stack:

Q:Why is Caddy 2 Modern Edge Webserver & Automatic TLS Standard critical for AI coding assistants?

Modern edge reverse proxy and TLS termination with Caddy 2. Leverages automatic ACME certificates, zero-downtime reloads, memory-safe Go architecture, and concise Caddyfile directives with HTTP/3 support. Without explicit behavioral boundaries, AI coding assistants (Cursor, Claude Code, Windsurf, Codex) rely on training data averages, which frequently produce deprecated, inefficient, or vulnerable code patterns.

Q:How does adopting this rule prevent AI hallucinations?

This rule explicitly declares what the AI must avoid (AI writes bloated Apache configs or fragile manual certbot cron scripts that fail during certificate renewal.) and prescribes verified positive examples. Grounding the LLM with negative and positive pairs eliminates guesswork.

Q:Which AI coding environments are supported?

This specification is multi-platform compatible: Cursor (.cursor/rules/*.mdc & .cursorrules), Anthropic Claude Code (CLAUDE.md), Windsurf (.windsurfrules), Codex / Cline (AGENTS.md), and GitHub Copilot (.github/copilot-instructions.md).

Q:Can I combine this rule with other technology stacks?

Yes. Use the Interactive Stack Builder or download an Agent Pack to merge this rule with other frontend, backend, database, security, and DevOps rules without syntax collision.

Open Specification · CC BY 4.0·Free for Personal, Team & Commercial In-Repo Use

Citation & Open Source Attribution Guidelines

This specification is licensed under Creative Commons Attribution 4.0 International (CC BY 4.0). You are completely free to adapt and share this rule in your workspace. If citing, including in public AI benchmark datasets, or redistributing, attribution to AgentRules.org is required.

1 Rule in Stack

Caddy