Serving static files as requested by the proxy with Docker

1. Output of caddy version:

docker exec -it 5e6252c9fffd caddy version
v2.5.2 h1:eCJdLyEyAGzuQTa5Mh3gETnYWDClo1LjtQm2q9RNZrs=

2. How I run Caddy: With Docker

a. System environment: With Unraid

b. Command:

/usr/local/emhttp/plugins/dynamix.docker.manager/scripts/docker run -d --name='CaddyV2' --net='caddy' -e TZ="Europe/Paris" -e HOST_OS="Unraid" -e HOST_HOSTNAME="RkUnraidServer" -e HOST_CONTAINERNAME="CaddyV2" -e 'LOG_PATH'='/var/log/caddy' -l net.unraid.docker.managed=dockerman -l net.unraid.docker.icon='' -p '2080:80/tcp' -p '2443:443/tcp' -v '/mnt/user/Docker/conf/caddyv2/data':'/data':'rw' -v '/mnt/user/appdata/CaddyV2':'/config':'rw' -v '/mnt/user/Docker/conf/caddyv2/Caddyfile':'/etc/caddy/Caddyfile':'rw' 'caddy:alpine'

c. Service/unit/compose file:

Paste full file contents here.
Make sure backticks stay on their own lines,
and the post looks nice in the preview pane. -->

d. My complete Caddy config: {
	reverse_proxy Zola:8080 {
		@accel status 200
		handle_response @accel {
			root    * /app/public
			rewrite * /

3. The problem I’m having:

I have my Caddy running in a Docker.
And I have Zola running in a Docker too.

I try to redirect my to static file that was generated by Zola:

But it does not work, have you any idea?

How works path of root?
Is it possible that this is a problem when everything is Dockerized?

4. Error messages and/or full log output:

{"level":"error","ts":1661729127.8222263,"logger":"http.log.access.log1","msg":"handled request","request":{"remote_ip":"","remote_port":"55600","proto":"HTTP/2.0","method":"GET","host":"","uri":"/","headers":{"Accept":["text/html,application/xhtml+xml,application/xml;q=0.9,image/avif,image/webp,*/*;q=0.8"],"Accept-Encoding":["gzip, deflate, br"],"Upgrade-Insecure-Requests":["1"],"Sec-Fetch-Dest":["document"],"Te":["trailers"],"User-Agent":["Mozilla/5.0 (Windows NT 10.0; Win64; x64; rv:103.0) Gecko/20100101 Firefox/103.0"],"Accept-Language":["fr,fr-FR;q=0.8,en-US;q=0.5,en;q=0.3"],"Sec-Fetch-Mode":["navigate"],"Sec-Fetch-Site":["none"],"Sec-Fetch-User":["?1"]},"tls":{"resumed":false,"version":772,"cipher_suite":4865,"proto":"h2","server_name":""}},"user_id":"","duration":0.002639728,"size":0,"status":404,"resp_headers":{"Server":["Caddy"]}}
{"level":"info","ts":1661729127.9352758,"logger":"http.log.access.log1","msg":"handled request","request":{"remote_ip":"","remote_port":"55600","proto":"HTTP/2.0","method":"GET","host":"","uri":"/favicon.ico","headers":{"Accept":["image/avif,image/webp,*/*"],"Accept-Encoding":["gzip, deflate, br"],"Te":["trailers"],"User-Agent":["Mozilla/5.0 (Windows NT 10.0; Win64; x64; rv:103.0) Gecko/20100101 Firefox/103.0"],"Accept-Language":["fr,fr-FR;q=0.8,en-US;q=0.5,en;q=0.3"],"Referer":[""],"Sec-Fetch-Dest":["image"],"Sec-Fetch-Mode":["no-cors"],"Sec-Fetch-Site":["same-origin"]},"tls":{"resumed":false,"version":772,"cipher_suite":4865,"proto":"h2","server_name":""}},"user_id":"","duration":0.000205652,"size":0,"status":0,"resp_headers":{"Server":["Caddy"]}}

5. What I already tried:

I tried to change path of root many times but nothing change.

6. Links to relevant resources:

From a quick reading, Zola seems to just generate a static site. It doesn’t run a server. So using reverse_proxy doesn’t make sense, because that requires there to be a server for Caddy to connect to.

What you should do is mount the built static site as a volume in your Caddy container, then just serve it with root + file_server. I recommend mounting the files to /srv. {
	root * /srv
	encode gzip

That should probably be all you need.

1 Like

I hadn’t thought of doing that, it’s a good alternative, thank you, I applied that :slight_smile:

P.S.: Zola offers a small internal server via the serve command.

I think the serve command is just meant for local development, not for production. It’s designed to be handed to another server that can serve it statically, and probably more efficiently.

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