Empty response for file server (Windows + WSL + Docker)

1. Caddy version (v2.1.1):

2. How I run Caddy:

a. System environment:

OS: Windows 10 pro => WSL 2 => Ubuntu => Docker
Docker image: php:7.4.8-fpm-alpine
Caddy is installed by commands in original alpine docker image

b. Command:

Docker entrypoint script

php-fpm -D
caddy run --config /etc/caddy/Caddyfile --adapter caddyfile

c. Service/unit/compose file:

FROM php:7.4.8-fpm-alpine

# Caddy install
RUN apk add --no-cache ca-certificates mailcap

ENV CADDY_DIST_COMMIT 80870b227ded910971ecace4a0c136bf0ef46342

RUN set -eux; \
	mkdir -p \
		/config/caddy \
		/data/caddy \
		/etc/caddy \
		/usr/share/caddy \
	; \
	wget -O /etc/caddy/Caddyfile "https://github.com/caddyserver/dist/raw/$CADDY_DIST_COMMIT/config/Caddyfile"; \
	wget -O /usr/share/caddy/index.html "https://github.com/caddyserver/dist/raw/$CADDY_DIST_COMMIT/welcome/index.html"

# https://github.com/caddyserver/caddy/releases

RUN set -eux; \
	apkArch="$(apk --print-arch)"; \
	case "$apkArch" in \
		x86_64)  binArch='amd64'; checksum='41f2442c52daf5a36d07af5024711072925997d8b5a7bd459994b000cfee1cb63d0c97d1b54b172c59b6b02a0f0eab285141a8cd3fc23cbca684f824c7b21b75' ;; \
		armhf)   binArch='armv6'; checksum='91b69356155b4909feec8c4e5674a52d13c75b5c4bedfa3c7be2615a18cecbb58212de753d288ecd355502412d33bde9beed713055263636039ee4c47466ca90' ;; \
		armv7)   binArch='armv7'; checksum='e45d8c8ac9fab83a26660531ef117dd0fbcaf81e442bb01f0d068afda6c507e692105e0c7f5fb86f227cf7693bff12b63647377e72571dc98c2dd0b6a7d76d81' ;; \
		aarch64) binArch='arm64'; checksum='8d9d873e701ab2dfe6046c5f6a9bbd19dd2aef7e4c57640c897e70cc5d2775353f0c467779e2fba4c024c9de89d2b1d64c1b46568dda65e6f5a114f13b239c6d' ;; \
		ppc64el|ppc64le) binArch='ppc64le'; checksum='30248cca16ec07e1e9aee0dabaaf0959f2f3622aafbdd9dac9135a4f2117ca3cc5b5bbfb8c94d45ea2c1abf61840587885f2db7fec420cd00918819cd39bfc92' ;; \
		s390x)   binArch='s390x'; checksum='f4e16ad4f03f13cbe463efb8577d99f22a30161916cde10f5a0c838f7c57022b572b9a18d25fb20925aef4a5366537948ffdd4a191b3d5205ab9ab980406ca4b' ;; \
		*) echo >&2 "error: unsupported architecture ($apkArch)"; exit 1 ;;\
	esac; \
	wget -O /tmp/caddy.tar.gz "https://github.com/caddyserver/caddy/releases/download/v2.1.1/caddy_2.1.1_linux_${binArch}.tar.gz"; \
	echo "$checksum  /tmp/caddy.tar.gz" | sha512sum -c; \
	tar x -z -f /tmp/caddy.tar.gz -C /usr/bin caddy; \
	rm -f /tmp/caddy.tar.gz; \
	chmod +x /usr/bin/caddy; \
	caddy version

RUN [ ! -e /etc/nsswitch.conf ] && echo 'hosts: files dns' > /etc/nsswitch.conf

# See https://caddyserver.com/docs/conventions#file-locations for details

VOLUME /config
VOLUME /data


# Copy Caddyfile (configuration)
COPY Caddyfile /etc/caddy/Caddyfile

# Install php extensions
RUN docker-php-ext-install mysqli

WORKDIR /var/www

# Make temp dirs writable
#RUN chmod -R 755 temp log

# Entrypoin - start fpm & caddy
COPY entrypoint.sh /etc/entrypoint.sh
RUN chmod +x /etc/entrypoint.sh
ENTRYPOINT ["/etc/entrypoint.sh"]

d. My complete Caddyfile or JSON config:

http://fenix.local/ {
        root * /var/www
        file_server browse

3. The problem I’m having:

I reduced Caddyfile to minimal configuration but I’m still having a problem with serving static files. Caddy serving path tree (only main no subdirectories). But not serving any file (in root directory and subdirectories as well)

4. Error messages and/or full log output:

fenix_app_caddy | [17-Jul-2020 22:18:59] NOTICE: fpm is running, pid 9
fenix_app_caddy | [17-Jul-2020 22:18:59] NOTICE: ready to handle connections
fenix_app_caddy | {"level":"info","ts":1595024339.7708907,"msg":"using provided configuration","config_file":"/etc/caddy/Caddyfile","config_adapter":"caddyfile"}
fenix_app_caddy | {"level":"info","ts":1595024339.774168,"logger":"admin","msg":"admin endpoint started","address":"tcp/localhost:2019","enforce_origin":false,"origins":["localhost:2019","[::1]:2019",""]}
fenix_app_caddy | {"level":"info","ts":1595024339.77909,"logger":"http","msg":"server is listening only on the HTTP port, so no automatic HTTPS will be applied to this server","server_name":"srv0","http_port":80}
fenix_app_caddy | 2020/07/17 22:18:59 [INFO][cache:0xc0000b86c0] Started certificate maintenance routine
fenix_app_caddy | {"level":"info","ts":1595024339.7830777,"logger":"tls","msg":"cleaned up storage units"}
fenix_app_caddy | {"level":"info","ts":1595024339.7835448,"msg":"autosaved config","file":"/config/caddy/autosave.json"}
fenix_app_caddy | {"level":"info","ts":1595024339.7836044,"msg":"serving initial configuration"}

5. What I already tried:

At first I set up it with php-fpm and it worked except that file serving. So i reduced configuration to only serving files, but it is not working.

6. Links to relevant resources:

The problem is the trailing / you have on your site label. That is telling Caddy to set up a path matcher that matches exactly /. This means that any request that isn’t to the root will fail.

Path matching in Caddy v2 is exact-match, so you would need to append a * to make it match anything further. Or you can simplify by removing the path matcher altogether by just removing the trailing /.

Also, I’d recommend making use of multi-stage builds for your Dockerfile instead of copying it; it’ll be much easier to update and be more portable. Something like this should work (didn’t test it, just typed this up now, first time I’m seeing someone take the approach you’re taking with Caddy)

COPY --from caddy:2.1.1-alpine /usr/bin/caddy /usr/bin/caddy
COPY --from caddy:2.1.1-alpine /etc/caddy/Caddyfile /etc/caddy/Caddyfile

That can replace the whole RUN part from your Dockerfile.


It’s working :tada: I thought it verifies only domain.

Thank you for help and the multistage build tip.

1 Like

This topic was automatically closed after 30 days. New replies are no longer allowed.