Hi all!
1. The problem I’m having:
I am trying to host a statically generated next.js application using caddy within a docker. I am able to serve the index page and images, however none of the generated css files, html or js files will load, returning 404. Image files served in /images do work however.
Folder Structure:
_next
- i_2_F26rYhMex-Uq5Vn3V
- static
- chunks
- app
- pages
- css
- i_2_F26rYhMex-Uq5Vn3V
- media
images
nav
posts
index.html
This only happens in my docker environment. Using a caddyfile in the site folder itself with just the file_server directive works as intended on Windows.
I have tried the following in my caddy file:
blg.domsweeney.fyi, img.domsweeney.fyi, arts.domsweeney.fyi, tech.domsweeney.fyi {
root * /srv/blog
file_server
try_files {path} /index.html
}
blg.domsweeney.fyi, img.domsweeney.fyi, arts.domsweeney.fyi, tech.domsweeney.fyi {
handle {
root * /srv/blog
file_server
try_files {path} /index.html
}
handle /_next/* {
root * /srv/blog/_next
file_server
}
handle /nav/* {
root * /srv/blog/nav
file_server
}
handle /posts/* {
root * /srv/blog/posts
file_server
}
}
2. Error messages and/or full log output:
Requests for javascript and css files within the _next, nav and posts folders return 404 request status. Images in the /images folder serve correctly.
3. Caddy version:
v2.8.4
4. How I installed and ran Caddy:
Installed through docker
services:
caddy:
container_name: "caddy"
image: caddy:latest
restart: unless-stopped
cap_add:
- NET_ADMIN
ports:
- "80:80"
- "443:443"
- "443:443/udp"
volumes:
- ./Caddyfile:/etc/caddy/Caddyfile
- /srv/botwork:/srv/botwork
- ./site:/srv
- caddy_data:/data
- caddy_config:/config
- ./certs:/etc/ssl/certs
- /srv/blog:/srv/blog
volumes:
caddy_data:
external: true
caddy_config:
a. System environment:
Ubuntu 22.04.2 LTS, Docker 27.3.1
d. My complete Caddy config:
blg.domsweeney.fyi, img.domsweeney.fyi, arts.domsweeney.fyi, tech.domsweeney.fyi {
handle {
root * /srv/blog
file_server
try_files {path} /index.html
}
handle_path /next/* {
root * /_next
file_server
}
handle_path /nav/* {
root * /nav
}
handle_path /posts/* {
root * /posts
}
#reverse_proxy http://192.168.1.118:8204
}