Hi all,
Thanks for creating Caddy!
1. The problem I’m having:
Trying to import files or snippets from other files into the main Caddyfile, without success.
The incentive is to use separate files (or even import specific snippets from external files) to allow extra functionality without bloating the main Caddyfile.
The docs are a little dull around importing files (import (Caddyfile directive) — Caddy Documentation)
I’ve tried several approaches:
- Tried to import a specific filename.
- Tried to import a folder with
foldername/*
with a few files in it. - Tried to create snippets in other files and import them to the main Caddyfile.
2. Error messages and/or full log output:
I’m usually getting either of those errors -
Error during parsing: File to import not found: methods.conf
No files matching import glob pattern","pattern":"folder/*"
3. Caddy version:
2.7.4-alpine
4. How I installed and ran Caddy:
a. System environment:
Docker compose:
CMD ["caddy", "run", "--config", "Caddyfile"]
b. Command:
docker compose up --build
c. Service/unit/compose file:
version: "3"
networks:
caddy:
services:
caddy:
image: caddy:2.7.4-alpine
env_file:
- .env.local
extra_hosts:
- "host.docker.internal:host-gateway"
restart: unless-stopped
build:
context: ./
args:
CADDYFILE: 'Caddyfile'
ports:
- "8000:80"
- "443:443"
volumes:
- ./Caddyfile:/etc/caddy/Caddyfile
- ./site:/srv
- caddy_data:/data
- caddy_config:/config
networks:
caddy:
volumes:
caddy_data:
caddy_config:
d. My complete Caddy config:
My folder structure looks like this:
= folder
== methods.config # file
= Caddyfile
# also tried placing the methods.config file here in the root folder.
{
debug
local_certs
admin off
}
:80 {
log
respond /health-check "healthy" 200
}
:443 {
log
import folder/*
#### also tried:
# import methods.conf
tls {
on_demand
}
reverse_proxy {
to {$DOMAIN}
header_up Host {$DOMAIN}
header_up Domain {http.request.host}
}
}
The content of the methods.conf file is currently:
@blockDelete method DELETE POST PATCH PUT
respond @blockDelete "Unauthorized" 405
I’ve tried different type of content within the file (snippets, handlers etc.) and also to move the import around or change the folder/file structures a few this, but the above should be the minimum reproducible example