1. Caddy version (caddy version
):
Latest Docker version (v2.0.0)
2. How I run Caddy:
a. System environment:
Docker, on Debian Buster
b. Command:
docker-compose up
c. Service/unit/compose file:
services:
caddy:
container_name: caddy
image: caddy:latest
restart: unless-stopped
ports:
- "80:80"
- "443:443"
volumes:
- ../volumes/caddy/Caddyfile:/etc/caddy/Caddyfile
- ../volumes/caddy/config:/config
- ../volumes/caddy/data:/data
# php-fpm roots
- ../volumes/nextcloud/html:/php-fpm-root/nextcloud
Note the last line, where I am bind mounting the html root of nextcloud into Caddy. I do the same for the nextcloud container, but into /var/www/html/
instead of /php-fpm-root/nextcloud
d. My complete Caddyfile or JSON config:
# /etc/caddy/Caddyfile
# Global config
{
# Let's Encrypt email
email myemail@example.com
acme_ca https://acme-staging-v02.api.letsencrypt.org/directory
}
cloud.example.com {
root * /php-fpm-root/nextcloud/
file_server
php_fastcgi nextcloud:9000 {
transport fastcgi {
root /var/www/html/ # This doesn't work!
}
}
header {
# enable HSTS
Strict-Transport-Security max-age=31536000;
}
redir /.well-known/carddav /remote.php/dav 301
redir /.well-known/caldav /remote.php/dav 301
# .htaccess / data / config / ... shouldn't be accessible from outside
@forbidden {
path /.htaccess
path /data/*
path /config/*
path /db_structure
path /.xml
path /README
path /3rdparty/*
path /lib/*
path /templates/*
path /occ
path /console.php
}
respond @forbidden 404
}
3. The problem Iām having:
I have Caddy running in a Docker container, as well as nextcloud in a container. I have the nexctcloud html directory shared between the two containers, bind mounted at ../volumes/nextcloud/html
. For the nextcloud container, this goes to /var/www/html/
, whereas in the Caddy container it goes to /php-fpm-root/nextcloud/
.
Back in Caddy V1, as far as I can tell you were able to do something like this:
root /php-fpm-root/nextcloud/
fastcgi / nextcloud:9000 php {
root /var/www/html/
}
That way, Caddy serves the static files from /php-fpm-root/nextcloud/
, but for fastcgi in the nextcloud container, the files are located at /var/www/html/
. I see that thereās an expanded way of doing php_fastcgi
, and this does seem to work, but that literally doubles the size of the Caddyfile. I was wondering if it is possible to do some sort of a root directive in the php_fastcgi
directive, as you could in V1.
4. Error messages and/or full log output:
{"level":"info","ts":1589669822.9492817,"msg":"using provided configuration","config_file":"/etc/caddy/Caddyfile","config_adapter":"caddyfile"}
run: adapting config using caddyfile: parsing caddyfile tokens for 'php_fastcgi': /etc/caddy/Caddyfile:38 - Error during parsing: transport already specified
{"level":"info","ts":1589670658.2529993,"msg":"using provided configuration","config_file":"/etc/caddy/Caddyfile","config_adapter":"caddyfile"}
run: adapting config using caddyfile: parsing caddyfile tokens for 'php_fastcgi': /etc/caddy/Caddyfile:38 - Error during parsing: unrecognized subdirective root
5. What I already tried:
I tried the above Caddyfile (which doesnāt work, first error above), as well as:
php_fastcgi nextcloud:9000 {
root /var/www/html/
}
(whcih also doesnāt work, second error above). I also tried the expanded form, which I think works but isnāt going to be fantastic once I add all my other php sites. I also tried just mounting the nextcloud html directory right into /var/www/html/
in Caddy, and that works too, however if any other container comes around that also uses /var/www/html/
, I wonāt be able to use it.
6. Links to relevant resources:
V1 was like this: Nextcloud via Docker and Caddy Ā· GitHub
7. Final Thoughts
This wasnāt so much a call for help as it was a question. Iād like to be able to override the root path for php_fastcgi
, without having to rewrite the whole thing in expanded form. Is that possible?