Skip to content

Caddy

September 29, 2023
June 10, 2023

Caddy 2 is a powerful, enterprise-ready, open source web server with automatic HTTPS written in Go

Caddy

Caddy used to add Sponsor header and use different license for pre-built binaries
https://www.reddit.com/r/golang/comments/bgz0cd/announcing_caddy_10_caddy_2_and_caddy_enterprise/
Version 2.0 was released in May 2020, seems to have better community support

TODO: remove v1 docs (prior to May 2020)

Caddy - The Ultimate Server with Automatic HTTPS
prebuild library from download page are licensed differently
caddyserver/caddy: Fast and extensible multi-platform HTTP/1-2-3 web server with automatic HTTPS
caddyserver/caddy-docker: Source for the official Caddy v2 Docker Image
caddyserver/dist: Resources for packaging and distributing Caddy systemd unit file

FROM caddy:2-builder-alpine AS builder

RUN xcaddy build \
 --with github.com/greenpau/caddy-auth-jwt \
 --with github.com/greenpau/caddy-auth-portal \
 --with github.com/aksdb/caddy-cgi \
 --with github.com/abiosoft/caddy-json-parse \
 --with github.com/greenpau/caddy-trace \
 --with github.com/RussellLuo/caddy-ext/ratelimit \
 --with github.com/chukmunnlee/caddy-openapi \
 --with github.com/lucaslorentz/caddy-docker-proxy/plugin \
 --with github.com/casbin/caddy-authz \
 --with github.com/mholt/caddy-l4 \
 --with github.com/mholt/caddy-ratelimit

FROM caddy:2-alpine

# overwrites caddy with my custom build
COPY --from=builder /usr/bin/caddy /usr/bin/caddy
https://caddyserver.com/download?\
  package=github.com%2Fgreenpau%2Fcaddy-auth-jwt&\
  package=github.com%2Fgreenpau%2Fcaddy-auth-portal&\
  package=github.com%2Faksdb%2Fcaddy-cgi%2Fv2&\
  package=github.com%2Fabiosoft%2Fcaddy-json-parse&\
  package=github.com%2Fgreenpau%2Fcaddy-trace&\
  package=github.com%2FRussellLuo%2Fcaddy-ext%2Fratelimit&\
  package=github.com%2Fchukmunnlee%2Fcaddy-openapi&\
  package=github.com%2Flucaslorentz%2Fcaddy-docker-proxy%2Fplugin%2Fv2&\
  package=github.com%2Fcasbin%2Fcaddy-authz%2Fv2&\
  package=github.com%2Fmholt%2Fcaddy-l4&\
  package=github.com%2Fmholt%2Fcaddy-ratelimit

Welcome โ€” Caddy Documentation
Getting Started โ€” Caddy Documentation
Upgrading to Caddy 2 โ€” Caddy Documentation
Caddy Community
Top Wiki topics - Caddy Community

Anyone else dislike v2? - Help - Caddy Community
For Mastodon Caddy Setting file. (Based on official Nginx configuration example) [Last Update: May 16, 2020] v1 -> v2
Upgrading to Caddy 2 โ€” Caddy Documentation

Caddy offers TLS, HTTPS, and more in one dependency-free Go Web server โ€“ Ars Technica

Troubleshooting

see ssl-tls.md#ssl-checkers

Do check SSL cert with SSL checkers as browser may allow revoked cert due to caching, but some anti-virus software will block it.

In case of Caddy not renewing revoked certificate, remove ~/.local/share/caddy/certificates/acme-v02.api.letsencrypt.org-directory/<domain> manually.

Config

Caddyfile Quick-start โ€” Caddy Documentation
Caddyfile Tutorial โ€” Caddy Documentation
The Caddyfile โ€” Caddy Documentation
Caddyfile Concepts โ€” Caddy Documentation

API Quick-start โ€” Caddy Documentation
API โ€” Caddy Documentation

JSON Config Structure - Caddy Documentation

Command Line โ€” Caddy Documentation

caddy run --config /path/to/Caddyfile
caddy start --config /path/to/Caddyfile  # in background
caddy file-server browse

Top Wiki topics - Caddy Community
So You Want to Write a Caddyfile - Wiki - Caddy Community
Composing in the Caddyfile - Wiki - Caddy Community

CORS

Caddy v2.1 CORS whitelist use import directive
Implementing CORS whitelist in Caddy v2 - Help - Caddy Community including 2.0 solution

Videos

Provo Linux User Group - 2/16/16 - Matt Holt - "Caddy" - YouTube
Caddy server Git add-on tutorial. - YouTube

Docker

Max Mehl | Docker2Caddy - An automatic Reverse Proxy for Docker containers
fsfe-system-hackers/docker2caddy: Background script that checks Docker containers running on the host and creates their Caddy reverse proxy config - docker2caddy - FSFE Git Service

Karan Sharma | How I expose services while self hosting

Module/Plugin

Extending Caddy โ€” Caddy Documentation

Modules - Caddy Documentation built-in modules
Download Caddy select bundled modules
caddyserver/xcaddy: Build Caddy with plugins

mholt/caddy-l4: Layer 4 (TCP/UDP) app for Caddy
Combining the layer4 and http apps (SSL pass through + http file_server/reverse_proxy) - Help - Caddy Community
Https Termination ยท Issue #3 ยท mholt/caddy-l4

abiosoft/caddy-git: git middleware for Caddy for deployment

mholt/caddy-ratelimit: HTTP rate limiting module for Caddy 2
caddy-ext/ratelimit at master ยท RussellLuo/caddy-ext
greenpau/caddy-auth-portal: Authentication Plugin for Caddy v2 implementing Form-Based, Basic, Local, LDAP, OpenID Connect, OAuth 2.0 (Github, Google, Facebook, Okta, etc.), SAML Authentication
greenpau/caddy-auth-jwt: JWT Authorization Plugin for Caddy v2
lucaslorentz/caddy-docker-proxy: Caddy as a reverse proxy for Docker

casbin/caddy-authz: Caddy-authz is a middleware for Caddy that blocks or allows requests based on access control policies.
casbin/casbin: An authorization library that supports access control models like ACL, RBAC, ABAC in Golang

How to use DNS provider modules in Caddy 2 - Wiki - Caddy Community
caddy-dns
mholt/caddy-dynamicdns: Caddy app that keeps your DNS records (A/AAAA) pointed at itself.

Tips and Tricks

Best practice tips/help - Help - Caddy Community

Cascading Caddy server results in empty 200 response
Why does caddy return an empty 200 response for a non-configured host? - Help - Caddy Community

v1

Command Line Interface - Caddy v1
caddyserver/examples: Simple guided examples of how to use Caddy v1

abiosoft/caddy
zzrot/alpine-caddy

Simply Secure ยป Linux Magazine
Today I became a Go developer, with vim and Caddy
A Look Inside Caddy, a Web Server Written in Go

# OBSOLETE v1 instructions
curl https://getcaddy.com | bash -s personal http.cors,http.expires,http.filemanager,http.filter,http.forwardproxy,http.git,http.hugo,http.jwt,http.locale,http.login,http.minify

mkdir caddy; cd caddy
wget https://caddyserver.com/download/linux/amd64 -O caddy_linux_amd64.tar.gz
tar xzf caddy_linux_amd64.tar.gz

./caddy browse -log ./log -port 80 -root <WWW_ROOT>