I try to start with caddy v2 official docker image, but how to configure it without caddyfile?
I hoped it would be possible to pass configuration by ENV VARS or CMD?
So how to configure Caddy v2 to serve static files from local document root and pass PHP to a php-fpm container without the need of a included caddyfile?
Well, you need to configure Caddy somehow. Your options are either using a Caddyfile as config, a JSON file as config, or using the admin API to push configuration changes.
You can set environment variables and use them inside your Caddyfile or JSON configs with the
Caddy does have special CLI commands to run a simple file server or reverse proxy, but those are just meant as simple shortcuts. I don’t think we’ll elaborate on those too much, it’s not hard to use an actual config file.
Why isn’t it possible to pass a caddy v2 config string (JSON) instead of a config file? Prepare / validate config and just pass as a CLI
For testing I added a simple caddyfile
root * /srv
But get a strange behavior… php code is parsed and Caddy v2 doen’t return the rendered code. It offers the result as file download?
Any idea why caddy (v2) or php-fpm should do that? Is it php-fpm or caddy related?
It’s a docker setup with caddy (v1) reverse proxy and a caddy v2 webserver backend working togester with a php-fpm container. So maybe caddy v1 → caddy v2 related?
date: Mon, 13 Apr 2020 14:06:57 GMT
status: 200 OK
You can pass a JSON config file using
caddy run --config your-json-file.json. Just replace the default command when running with Docker.
For that Caddyfile, it looks fine to me. I know nothing about your environment so there’s not much I can do to help. You’ll need to elaborate and give us enough information so we could replicate your issue
I tested it with a config string, but caddy try to open a file instead of use the given config string. Maybe it could be added as feature to check if string or file is given? Load config from string would be nice, because I don’t need to add a file to docker volume.
You can use the admin API for that, but you still need a config file to change the admin API endpoint from
localhost:2019 to something wider (since
localhost will only allow connections from inside the container). You could do this by writing a Dockerfile
FROM caddy/caddy that sets a default config file to set the admin endpoint to a different address.
That said, I don’t understand what problem you have with passing the config as a file via a volume, that’s standard practice.
This topic was automatically closed 30 days after the last reply. New replies are no longer allowed.