---
title: Caddy
url: 'https://www.handtrixxx.com/en/wiki/self-hosted/caddy'
markdown: 'https://www.handtrixxx.com/en/wiki/self-hosted/caddy.md'
lang: en
date: '2023-04-09'
description: 'Caddy Today I describe what a reverse proxy is and why it must not be missing in your Docker landscape. After several years of using both Traefik and the Nginx Proxy Manager as reverse proxy for my Docker containers, I have now landed at Caddy. What bothered me about the Nginx Proxy Manager was tha…'
---

#  Caddy 

Today I describe what a reverse proxy is and why it must not be missing in your Docker landscape. After several years of using both Traefik and the Nginx Proxy Manager as reverse proxy for my Docker containers, I have now landed at Caddy. What bothered me about the Nginx Proxy Manager was that for configuration only the web UI is available. That brought me to the limits more often in backup/restore scenarios, which ultimately led to staging a clicking-orgy anew every time. What bothered me about Traefik in turn was the bloated configuration, as well as the many labels that have to be added at every container to be considered. Caddy offers the desired flexibility with a CLI and an API, and is also easy to back up and restore.

![](https://www.handtrixxx.com/user/pages/wiki/02.self-hosted/caddy/02-caddy-open-graph.jpg)

## compose.yml file

```yaml
<span class="hljs-attr">services:</span>
  <span class="hljs-attr">caddy:</span>
    <span class="hljs-attr">container_name:</span> <span class="hljs-string">caddy</span>
    <span class="hljs-attr">image:</span> <span class="hljs-string">caddy:latest</span>
    <span class="hljs-attr">restart:</span> <span class="hljs-string">unless-stopped</span>
    <span class="hljs-attr">ports:</span>
      <span class="hljs-bullet">-</span> <span class="hljs-string">"80:80"</span>
      <span class="hljs-bullet">-</span> <span class="hljs-string">"443:443"</span>
      <span class="hljs-bullet">-</span> <span class="hljs-string">"443:443/udp"</span>
    <span class="hljs-attr">volumes:</span>
      <span class="hljs-bullet">-</span> <span class="hljs-string">./Caddyfile:/etc/caddy/Caddyfile</span>
      <span class="hljs-bullet">-</span> <span class="hljs-string">./caddy_data:/data</span>
      <span class="hljs-bullet">-</span> <span class="hljs-string">./caddy_config:/config</span>
    <span class="hljs-attr">networks:</span>
      <span class="hljs-bullet">-</span> <span class="hljs-string">caddy</span>
<span class="hljs-attr">networks:</span>
  <span class="hljs-attr">caddy:</span>
    <span class="hljs-attr">name:</span> <span class="hljs-string">caddy</span>
    <span class="hljs-attr">driver:</span> <span class="hljs-string">bridge</span>
    <span class="hljs-attr">ipam:</span>
      <span class="hljs-attr">config:</span>
        <span class="hljs-bullet">-</span> <span class="hljs-attr">subnet:</span> <span class="hljs-number">172.19</span><span class="hljs-number">.0</span><span class="hljs-number">.0</span><span class="hljs-string">/16</span>
          <span class="hljs-attr">gateway:</span> <span class="hljs-number">172.19</span><span class="hljs-number">.0</span><span class="hljs-number">.1</span>
```

## Commands

To reload Caddy after making changes to your Caddyfile:

```bash
docker <span class="hljs-built_in">exec</span> -w /etc/caddy caddy caddy fmt --overwrite
docker <span class="hljs-built_in">exec</span> -w /etc/caddy caddy caddy reload
docker <span class="hljs-built_in">exec</span> -w /etc/caddy caddy caddy <span class="hljs-built_in">hash</span>-password -p password
```

## Why a reverse proxy for Docker containers?

Using a so-called reverse proxy for your own (Docker) container landscape should provide on the one hand flexibility and on the other hand increased security. The (virtual) network of the containers is divided into various zones, so that e.g. database instances are not directly reachable from the internet. Also e.g. several WordPress installations can be operated in parallel without getting in each other's way somehow. Both are illustrated in the following diagram:

![](https://www.handtrixxx.com/user/pages/wiki/02.self-hosted/caddy/01-caddy.png)

In addition, access to the self-hosted websites should work exclusively via the encrypted HTTPS protocol. The certificates required for that are managed and updated for us fully automatically by a modern reverse proxy solution.

## How do I install and operate Caddy as a reverse proxy?

First we set up a dedicated network for Caddy and the containers that should be publicly reachable under a desired name (here \\"caddy\\") with the following command: `docker network create caddy`. This name only you see in your configuration files and in Docker.

We also provide Caddy itself via a Docker container on which we expose ports 80 and 443. A possible Docker Compose file \\"compose.yml\\" for that can look as shown above.

Before we start the container, we create a file \\"Caddyfile\\" in the same directory. You have to adapt this to your needs; it orientates itself here on the example shown above:

```javascript
{
    # TLS Options
    email deine.email@provider.com
}

(wordpress) {
    header {
        Cache-Control <span class="hljs-string">"public, max-age=3600, must-revalidate"</span>
    }
}

quickscot.de, www.quickscot.de {
    <span class="hljs-keyword">import</span> wordpress
    reverse_proxy wordpresscontainer1:<span class="hljs-number">80</span>
}

niklas-stephan.de, www.niklas-stephan.de {
    <span class="hljs-keyword">import</span> wordpress
    reverse_proxy wordpresscontainer3:<span class="hljs-number">80</span>
}
```

Now we can start the container with the following command: `docker compose up -d`. If something does not work, checking the log file helps with: `docker compose logs`.

For problems a look into the Caddy community also helps, which provides many problem treatments and configuration examples: <https://caddy.community/>.

If you make changes or additions to the Caddyfile, you do not have to restart the complete container every time. You avoid downtimes with the following command, which reloads the configuration live:

```bash
docker <span class="hljs-built_in">exec</span> -w /etc/caddy caddy caddy reload
```

## Caddyfile

```json
{
    # TLS Options
    email niklas.stephan@gmail.com
}

(wordpress) {
    header {
        Cache-Control <span class="hljs-attr">"public, max-age=7200, must-revalidate"</span>
    }
}

(mail-backend) {
    reverse_proxy 172.19.0.1:<span class="hljs-number">8085</span>
}

(trusted_proxy_list) {
    trusted_proxies 172.19.0.0/24
}

cloud.niklas-stephan.de {
    reverse_proxy 172.19.0.1:<span class="hljs-number">9200</span>
}

docs.niklas-stephan.de {
    reverse_proxy docsniklas-stephande-outline-1:<span class="hljs-number">80</span>
}

collabora.niklas-stephan.de {
    reverse_proxy 172.19.0.1:<span class="hljs-number">9980</span>
}
wopiserver.niklas-stephan.de {
    reverse_proxy 172.19.0.1:<span class="hljs-number">9300</span>
}

docker.handtrixxx.com {
    reverse_proxy arcane:<span class="hljs-number">3552</span>
}

node.handtrixxx.com {
    reverse_proxy node:<span class="hljs-number">1880</span>
}

ac-malchsee.de, www.ac-malchsee.de {
    import wordpress
    reverse_proxy malchsee-app:<span class="hljs-number">80</span>
}

frau-eule.de, www.frau-eule.de {
    import wordpress
    reverse_proxy fraueulede-app:<span class="hljs-number">80</span>
}

new.frau-eule.de {
    import wordpress
    reverse_proxy fraueule-app:<span class="hljs-number">80</span>
}

handtrixxx.com, www.handtrixxx.com {
    reverse_proxy handtrixxx:<span class="hljs-number">80</span>
}

auth.handtrixxx.com {
    reverse_proxy authentik-server:<span class="hljs-number">9000</span>
}

home.handtrixxx.com {
    reverse_proxy wg-easy:<span class="hljs-number">8123</span>
}

music.handtrixxx.com {
    reverse_proxy wg-easy:<span class="hljs-number">8095</span>
}

keys.handtrixxx.com {
    reverse_proxy vaultwarden:<span class="hljs-number">80</span>
}

dav.handtrixxx.com {
    reverse_proxy radicale:<span class="hljs-number">5232</span>
}

mail.handtrixxx.com,
mail.niklas-stephan.de,
mail.quickscot.de,
mail.quicksilvers.de,
mail.ac-malchsee.de,
mail.frau-eule.de {
    import mail-backend
}

autodiscover.mail.handtrixxx.com,
autoconfig.mail.handtrixxx.com,
autodiscover.handtrixxx.com,
autoconfig.handtrixxx.com {
    import mail-backend
}

webmail.handtrixxx.com {
    reverse_proxy roundcube:<span class="hljs-number">80</span>
}

stalwart.handtrixxx.com {
    reverse_proxy stalwart:<span class="hljs-number">8080</span>
}

photos.handtrixxx.com {
    reverse_proxy immich-server:<span class="hljs-number">2283</span>
}

search.handtrixxx.com {
    reverse_proxy search-searxng:<span class="hljs-number">8080</span>
}

start.handtrixxx.com {
    reverse_proxy heimdall:<span class="hljs-number">80</span>
}

desktop.handtrixxx.com {
    reverse_proxy webtop:<span class="hljs-number">3000</span>
}

vpn.handtrixxx.com {
    reverse_proxy wg-easy:<span class="hljs-number">51821</span>
}

niklas-stephan.de, www.niklas-stephan.de {
    reverse_proxy app:<span class="hljs-number">3000</span>
}

quickscot.de, www.quickscot.de, quicksilvers.de, www.quicksilvers.de {
    import wordpress
    reverse_proxy quickscot-static:<span class="hljs-number">80</span>
}

stats.niklas-stephan.de, stats.ac-malchsee.de, stats.frau-eule.de, stats.handtrixxx.com, stats.quickscot.de {
    reverse_proxy matomo-web:<span class="hljs-number">80</span> {
        header_up X-Real-IP {remote_host}
        import trusted_proxy_list
    }
}

cdfox.bbraun.io {
    handle_path /ext/drawio<span class="hljs-comment">/* {
        @index_html path /ext/drawio/index.html
        handle @index_html {
            respond @unauthorized 401
        }
        reverse_proxy drawio:80
    }
    reverse_proxy cdfox:3000
}
</span>
```

 self-hostedwebservernetwork

---

## Navigation

- Parent: [Self-hosted](https://www.handtrixxx.com/en/wiki/self-hosted.md)
- Previous: [Artalk](https://www.handtrixxx.com/en/wiki/self-hosted/artalk.md)
- Next: [Calibre Web](https://www.handtrixxx.com/en/wiki/self-hosted/calibre-web.md)
