Hi, I’m fairly new to the Caddy community - congratulations on having a Discourse forum though!
I’m trying to deploy a Django web app using Caddy as the front end web server for its SSL/HTTPS abilities. The app is intended to run the same in local development, on the development server, and in staging and live environments, these of course all have different URLs so I’m attempting to use environment variables in a .env
file in order to pass in the URL to serve.
1. The problem I’m having:
The Caddyfile doesn’t appear to be being parsed properly when using the {$ENVIRONMENT_VARIABLE}
style of env var replacement. When I had hard-coded values in the Caddyfile it worked fine.
{
email {$LETSENCRYPT_EMAIL_ADDRESS}
acme_ca {$LETSENCRYPT_ENDPOINT:https://acme-v02.api.letsencrypt.org/directory}
}
{$SITE_DOMAIN} {
reverse_proxy http://django:8000
}
{$SITE_DOMAIN}/flower {
reverse_proxy http://flower:8888
}
The global section adds an email for LetsEncrypt, I am aiming for this to be not committed to the source code, hence using env var.
The Acme CA URL is also not hardcoded since I want to be able to use the LE staging endpoint in certain development environments so I don’t get rate-limited. I’m using what I hope is the correct syntax for setting a ‘default’ value of the Acme endpoint.
For some reason the {$SITE_DOMAIN}
replacement IS working and does seem to correctly obtain the environment variables and obtain a cert.
2. Error messages and/or full log output:
rcpch-audit-engine-caddy-1 | Error: adapting config using caddyfile: parsing caddyfile tokens for 'acme_ca': /etc/caddy/Caddyfile:3 - Error during parsing: Wrong argument count or unexpected line ending after 'acme_ca', import chain: ['']
I’m not using the import_chain
directive so I’m confused as to what the error means. I wonder if it’s something not parsing correctly, perhaps if I have used incorrect syntax. But I’ve consulted the docs and all examples I can find online.
If I remove the acme_ca
directive, the same error occurs, just in relation to the line above.
3. Caddy version:
v2.7.4
4. How I installed and ran Caddy:
Caddy is installed from the official Docker Hub image, as part of the Docker Compose setup
a. System environment:
Caddy is running in its own official image Docker container, within a Docker Compose setup. The Docker host is Ubuntu although that should not matter.
b. Command:
Caddy is being run by the docker compose up
command. Here is the relevant section of the docker-compose.yml
:
services:
# Caddy reverse proxy - web-facing SSL server
caddy:
depends_on:
- django
env_file:
- envs/local-dev.env
image: caddy
ports:
- "80:80"
- "443:443"
restart: always
volumes:
- caddy_data:/data/
- caddy_data:/config/
- ./Caddyfile:/etc/caddy/Caddyfile