Tested with
NetBox Community v4.2.5-Docker-3.2.0
The attached docker-compose.override.yml shows a full working example bundled with Caddy. Running it should make Netbox accessible at https://mydomain.net/netbox.
This variant of Caddy doesn't require a user-defined Caddyfile for configuration. Rather it dynamically derives the Caddyfile from aggregated Docker labels. See https://github.com/lucaslorentz/caddy-docker-proxy for more info.
Otherwise, follow the next section to configure an existing Caddy instance using a regular Caddyfile.
Assume your deployment is under /netbox:
Add to configuration/extra.py:
from os import environ
BASE_PATH = environ.get('BASE_PATH', '')Then merge the following with your own docker-compose.override.yml (or create one if it doesn't exist) to make health checker of Docker happy:
version: '3.4'
services:
netbox:
healthcheck:
test: "curl -f http://localhost:8080/netbox/api/ || exit 1"
environment:
BASE_PATH: '/netbox'Outside Caddy config (standard Caddyfile):
:80 {
handle /netbox/* {
encode zstd gzip # optional
reverse_proxy 127.0.0.1:8080
}
handle /netbox/static/* {
encode zstd gzip # optional
reverse_proxy 127.0.0.1:8080
uri strip_prefix /netbox
}
redir /netbox /netbox/
}The trick is to strip BASE_PATH on any requests to static resources.