Using Caddy for web sites and as Reverse proxy manager
Using Caddy as a http(s) server and a reverse proxy
Reverse‑proxy to a intranet server
Basic syntax (Caddyfile) For domain our-domain.com pointing to an internal server at xxx.xxx.xxx.xxx:port, a typical Caddy config looks like this:
our-domain.com {
reverse_proxy http://xxx.xxx.xxx.xxx:port
}or, if the backend listens on HTTPS:
our-domain.com {
reverse_proxy https://xxx.xxx.xxx.xxx:port
}This is exactly the same structure as localhost:port; you just replace localhost with the internal IP.
If problems
Most common issues and checks
If it “seems not to work”:
Test connectivity from the Caddy host Make sure you can reach the backend from the machine running Caddy:
curl -v http://xxx.xxx.xxx.xxx:port
# or
curl -vk https://xxx.xxx.xxx.xxx:portAllow the port in the firewall Ensure the intranet server allows traffic on port from Caddy’s IP (and that any local firewall / security group isn’t blocking it).
Use schemes correctly
If the backend server speaks plain HTTP, use http://….
If it speaks HTTPS, use https://… (and live with TLS between Caddy and backend, or explicitly disable cert verification if needed).
Optional: custom transport / timeouts
our-domain.com {
reverse_proxy {
to http://xxx.xxx.xxx.xxx:port
transport http {
dial_timeout 5s
}
}
}This can help when the backend is slow or unreachable.
Any catch?
Yes, Caddy is genuinely much simpler and cleaner than Nginx‑style setups for most reverse‑proxy use cases, and that intuitive feeling you’re having is pretty common.
What makes Caddy “easy” Single‑file config: The Caddyfile is human‑readable and usually very short for typical reverse proxies.
Automatic HTTPS: By default it gets and renews TLS certificates from Let’s Encrypt with no extra config.
Straightforward syntax: our-domain.com { reverse_proxy http://x.x.x.x:port } does exactly what it looks like.
Common “catches” to watch For most people, Caddy is easier and more pleasant than Nginx Proxy Manager (NPM), but there are a few trade‑offs:
Less GUI / click‑click admin
NPM gives you a web UI to manage domains, certificates, and proxies.
Caddy is mostly file‑driven (CLI / config), so you need to edit Caddyfile or use its API.
Dynamic services vs static config
If you constantly spin up new internal services and want zero‑config reverse‑proxy entries, NPM or Traefik may feel more “automatic.”
Caddy works best when you are okay adding a small config block per service.
Edge‑case features
Very advanced routing, low‑level headers, or complex load‑balancing rules can still be done in Caddy, but sometimes require more “DSL‑style” Caddy syntax than plain Nginx‑like configuration.
In short: yes, Caddy is really that simple for typical reverse‑proxy tasks, and the “catch” is mostly that it pushes you toward a clean declarative config rather than a GUI, which most people end up preferring once they get used to it.
On our intranet server we use apache with basic authentication. Could we do that authentication in caddy?
Yes, you can absolutely do the HTTP Basic Authentication in Caddy instead of in Apache. It’s actually quite clean and fits well with your current setup.
How to move basic auth to Caddy Instead of Apache doing Require valid‑user, you let Caddy prompt for a username / password before it forwards to the backend. The directive is basic_auth (or basic_auth in newer versions).
Example pattern
In your main Caddyfile or imported proxy.caddy
our-domain.com {
# Step 1: require basic auth
basicauth /* {
username $2a$14$xxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxx
}
# Step 2: reverse proxy to your intranet Apache
reverse_proxy http://xxx.xxx.xxx.xxx:port
}Key points:
/* means “all paths under this host” must be authenticated.
You must hash the password; Caddy does not accept plaintext passwords.
Run this once (replace mypassword with the real one):
caddy hash-password --plaintext mypasswordThen paste the hash into the Caddyfile like shown above.
Optional: apply auth only to certain paths
If you want only some paths protected (e.g., /admin), you can be more specific:
our-domain.com {
handle /admin* {
basicauth {
username $2a$14$xxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxx
}
}
reverse_proxy http://xxx.xxx.xxx.xxx:port
}This way, /admin/… is protected, and the rest of the site goes through unauthenticated.
Yes, you can move that Apache basic auth into Caddy, keep your Apache config simple, and still have the same login prompt for your intranet services.
You can easily define multiple users in Caddy’s basic_auth. Just lists more username + hash pairs inside the same block.
Basic syntax for multiple users
our-domain.com {
basic_auth {
alice $2a$14$xxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxx
bob $2a$14$yyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyy
charlie $2a$14$zzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzz
}
reverse_proxy http://xxx.xxx.xxx.xxx:port
}Each line is:
username <hashed_password>
Important notes:
!!! warning “You must hash the password with:”
caddy hash-password --plaintext mypasswordand paste the hash instead of mypassword.
These users are “either/or”: any matching username+password will be accepted.
You can reuse the same basic_auth block across multiple sites/snippets by importing it into your proxy.caddy or master Caddyfile.
Example: snippet for shared auth
If you have several intranet services that should share the same user set:
# In common.caddy
(MYUSERS) {
basic_auth {
alice $2a$14$xxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxx
bob $2a$14$yyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyy
}
}Then reuse it in each site:
internal1.our-domain.com {
import MYUSERS
reverse_proxy http://backend1:8080
}
internal2.our-domain.com {
import MYUSERS
reverse_proxy http://backend2:8080
}This way, all your .caddy files stay small and you manage users in one place.
Difference between basic_auth and forward_auth in Caddy
The main difference is:
basic_auth is Caddy’s built‑in HTTP Basic Authentication: username + password, checked directly inside Caddy using hashes. Simple, self‑contained, but not very feature‑rich.
forward_auth offloads authentication to a separate “auth gateway” (e.g., Authelia, Keycloak, your own service) that decides whether the request is allowed.
When to use basic_auth
Use basic_auth when:
You want a quick, static password gate for a site or path.
You’re okay with managing a small list of users directly in the Caddyfile.
You don’t need sessions, SSO, MFA, or role‑based access policies.
Example:
our-domain.com {
basic_auth {
alice $2a$14$xxxxxxxxxxxxxxxxxxxxxxxx
bob $2a$14$yyyyyyyyyyyyyyyyyyyyyyyy
}
reverse_proxy http://backend:8080
}When to use forward_auth
Use forward_auth when:
You want richer auth (sessions, SSO, 2FA, groups, etc.).
You already run an auth service (e.g., Authelia, Keycloak, Dex, or a custom app).
You want to reuse the same auth logic across many services.
Typical pattern:
our-domain.com {
forward_auth {
uri http://auth-gateway:9091/auth
copy_request_headers
}
reverse_proxy http://backend:8080
}Here Caddy sends a copy of the request to auth-gateway; if that service returns 200 OK, Caddy continues to the backend; if it returns 401 or 403, the user is blocked or redirected.
Simple comparison
| Feature | basic_auth | forward_auth |
|---|---|---|
| Feature basic_auth forward_auth | ||
| Where auth is handled | Inside Caddy | External auth service |
| Sessions / cookies No Yes (via the auth gateway) | ||
| SSO, MFA, groups, roles No Yes (whatever your auth service supports) | ||
| Config complexity Very low Higher (need an auth service) | ||
| Use case Simple static password gate Full‑featured auth / SSO setup |
In short:
Use basic_auth for “just a password” on a small number of trusted users.
Use forward_auth when you want a proper, flexible auth system (like Authelia) and let Caddy delegate authentication to it.