···11+# Caddy
22+33+To use Anubis with Caddy, stick Anubis between Caddy and your backend. For example, consider this application setup:
44+55+```mermaid
66+---
77+title: Caddy with Anubis in the middle
88+---
99+1010+flowchart LR
1111+ T(User Traffic)
1212+ TCP(TCP 80/443)
1313+ An(Anubis)
1414+ B(Backend)
1515+ Blocked
1616+1717+ T --> TCP
1818+ TCP --> |Traffic filtering| An
1919+ An --> |Happy traffic| B
2020+ An --> |Malicious traffic| Blocked
2121+```
2222+2323+Instead of your traffic going directly to your backend, it takes a detour through Anubis. Anubis filters out the "bad" traffic and passes the "good" traffic to the backend.
2424+2525+To set up Anubis with Docker compose and Caddy, start with a `docker-compose` configuration like this:
2626+2727+```yaml
2828+services:
2929+ caddy:
3030+ image: caddy:2
3131+ ports:
3232+ - 80:80
3333+ - 443:443
3434+ - 443:443/udp
3535+ volumes:
3636+ - ./conf:/etc/caddy
3737+ - caddy_config:/config
3838+ - caddy_data:/data
3939+4040+ anubis:
4141+ image: ghcr.io/techarohq/anubis:latest
4242+ pull_policy: always
4343+ environment:
4444+ BIND: ":3000"
4545+ TARGET: http://httpdebug:3000
4646+4747+ httpdebug:
4848+ image: ghcr.io/xe/x/httpdebug
4949+ pull_policy: always
5050+5151+volumes:
5252+ caddy_data:
5353+ caddy_config:
5454+```
5555+5656+And then put the following in `conf/Caddyfile`:
5757+5858+```Caddyfile
5959+# conf/Caddyfile
6060+6161+yourdomain.example.com {
6262+ tls your@email.address
6363+6464+ reverse_proxy http://anubis:3000 {
6565+ header_up X-Real-Ip {remote_host}
6666+ header_up X-Http-Version {http.request.proto}
6767+ }
6868+}
6969+```
7070+7171+If you want to protect multiple services with Anubis, you will need to either start multiple instances of Anubis (Anubis requires less than 32 MB of ram on average) or set up a two-tier routing setup where TLS termination is done with one instance of Caddy and the actual routing to services is done with another instance of Caddy. See the [nginx](./nginx.mdx) or [Apache](./apache.mdx) documentation to get ideas on how you would do this.
···11+# FROM caddy:2.10.0-builder AS builder
22+33+# RUN xcaddy build \
44+# --with github.com/lolPants/caddy-requestid
55+66+FROM caddy:2.10.0 AS run
77+88+# COPY --from=builder /usr/bin/caddy /usr/bin/caddy
99+COPY Caddyfile /etc/caddy/Caddyfile
···11+#!/usr/bin/env bash
22+33+# If the transient local TLS certificate doesn't exist, mint a new one
44+if [ ! -f ../pki/caddy.local.cetacean.club/cert.pem ]; then
55+ # Subshell to contain the directory change
66+ (
77+ cd ../pki \
88+ && mkdir -p caddy.local.cetacean.club \
99+ && \
1010+ # Try using https://github.com/FiloSottile/mkcert for better DevEx,
1111+ # but fall back to using https://github.com/jsha/minica in case
1212+ # you don't have that installed.
1313+ (
1414+ mkcert \
1515+ --cert-file ./caddy.local.cetacean.club/cert.pem \
1616+ --key-file ./caddy.local.cetacean.club/key.pem caddy.local.cetacean.club \
1717+ || go tool minica -domains caddy.local.cetacean.club
1818+ )
1919+ )
2020+fi
2121+2222+docker compose up --build