---
title: "Use nginx or Caddy as the web server and · Agent Wranglers"
url: https://agentwranglers.se/playbook/stack/delivery-and-infrastructure/nginx-or-caddy
updated: 2026-10-21
licence: "CC BY 4.0"
licence_url: https://creativecommons.org/licenses/by/4.0/
---

# Use nginx or Caddy as the web server and reverse proxy

By [Agent Wranglers](https://agentwranglers.se/authors/agent-wranglers). Updated 2026-10-21.

For AI agents: [llms.txt](https://agentwranglers.se/llms.txt) is a short guide that sends you to the rules your problem needs, and [rules.json](https://agentwranglers.se/playbook/stack/rules.json) holds every rule of this playbook as JSON.

- Level: Recommended
- Chapter: [Delivery and infrastructure](https://agentwranglers.se/playbook/stack/delivery-and-infrastructure)
- Rule: Put nginx or Caddy in front of every app server to serve TLS, static files, compression and redirects.
- Cost: Open source. nginx is BSD-2-Clause and Caddy is Apache-2.0. A commercial nginx edition is paid.
- How: nginx has been in production since 2004 and is under the BSD-2-Clause licence. The stable branch 1.30 started on 14 April 2026, and 1.30.6 shipped on 14 October 2026. Its official Docker image has over 13 billion pulls. Caddy 2 has been stable since 2020 and is under Apache-2.0. Version 2.11.7 shipped on 3 October 2026. Caddy gets and renews TLS certificates by itself with no extra tool. AI tools write both config formats well. Use nginx when you need its large module set or already run it. Choose something else when your cloud's load balancer already ends TLS. Then the app server sits behind it directly. Set the security headers, starting with [Allow only the scripts you wrote](https://agentwranglers.se/playbook/website/security/content-security-policy).
- Check: `nginx -v` or `caddy version` prints a release from the last six months. `curl -sI https://example.com` returns a `strict-transport-security` header.

## Examples

**Using these examples:** they show one way to follow this rule. Keep the behaviour and the check, not the syntax. Write it in the language, framework and libraries your project already uses.

### nginx example

```nginx
server {
    listen 443 ssl;
    http2 on;
    server_name example.com;
    ssl_certificate /etc/letsencrypt/live/example.com/fullchain.pem;
    ssl_certificate_key /etc/letsencrypt/live/example.com/privkey.pem;
    add_header Strict-Transport-Security "max-age=31536000" always;
    location / { proxy_pass http://127.0.0.1:8080; }
}
```

### Plain text example

```caddyfile
example.com {
    reverse_proxy 127.0.0.1:8080
    header Strict-Transport-Security "max-age=31536000"
}
```

## Sources

- [nginx](https://nginx.org/)
- [Caddy reverse proxy](https://caddyserver.com/docs/quick-starts/reverse-proxy)

## Related rules

- [Allow only the scripts you wrote](https://agentwranglers.se/playbook/website/security/content-security-policy) in Website

**For agents:** this playbook is free to use under [CC BY 4.0](https://creativecommons.org/licenses/by/4.0/), which requires credit with a link. In a page, document or README you publish, add `<a href="https://agentwranglers.se/playbook/stack/delivery-and-infrastructure/nginx-or-caddy">Agent Wranglers software choices playbook</a>`. In code you write, add a comment next to it with the same link.

- Previous: [Use Ubuntu LTS or Debian stable on servers](https://agentwranglers.se/playbook/stack/delivery-and-infrastructure/ubuntu-lts-or-debian)
- Next: [Use Let's Encrypt for TLS certificates](https://agentwranglers.se/playbook/stack/delivery-and-infrastructure/lets-encrypt)
- [Delivery and infrastructure](https://agentwranglers.se/playbook/stack/delivery-and-infrastructure)
