Running Plausible with Caddy

This article wasn't updated in the last 3 ¾ years. Please double check if the content is still up-to-date.

If you find any error, please send me a quick heads-up.

First install Plausible using the official self-hosted installation docs. I installed it using docker-compose, because it heavily simplifies hosting and updates.

Update Plausible config

The first thing we need to do is to use the most recent version of plausible in the docker-compose.yml. First look up the most recent version number of plausible in the releases here and use that version number in the docker compose config.

At the time of writing, the most recent version is v1.4.4:

# ...
plausible:
    image: plausible/analytics:v1.4.4

The next thing we need to do is to map the port of the web container to something that won’t clash with anything. In my case, I want to use 8123:

# ...
plausible:
    # ...
    ports:
        - 8123:8000

Inside the container plausible exposes the web app under port 8000, and we want to expose it outside the container at port 8123. So after this change, plausible is running under 127.0.0.1:8123.

The only thing left now is to pass the request through Caddy to the plausible container.

Configuring Caddy

First we use a basic setup of caddy, by setting some default headers and removing some.

Edit the file at /etc/caddy/Caddyfile.

First we want to use HTTP3 and we also set a global contact mail (that’s important for the SSL certs etc):

{
    servers {
        protocol {
            experimental_http3
        }
    }

    email [email protected] # use your own email here
}

The only thing left to do is to pass the requests to our domain through to plausible. Use your own domain here instead of metrics.example.org:

metrics.example.org {
    reverse_proxy http://127.0.0.1:8123
}

Now you need to reload the caddy config and you can access plausible under your domain.