1. The problem I’m having:
The suggested config for handling reverse proxy errors seems not to take into account the reverse proxy status, overwriting it with 200. How do I make Caddy respond with the reverse proxy status? I tried with the status
directive, but it seems not to be allowed in the handle_response
context.
2. Error messages and/or full log output:
curl
on Caddy
curl -I localhost:8080
HTTP/1.1 200 OK
Accept-Ranges: bytes
Content-Length: 4836
Content-Type: text/html; charset=utf-8
Etag: "sqz3ws3qc"
Last-Modified: Fri, 31 Jan 2025 22:02:52 GMT
Server: Caddy
Date: Mon, 10 Feb 2025 11:05:00 GMT
curl
on reverse proxy
> curl -I localhost:3000
HTTP/1.1 404 Not Found
content-type: text/html; charset=UTF-8
x-request-id: 6a70f078-c685-4b43-9de0-42d63d33f64e
x-runtime: 0.000422
Content-Length: 4836
3. Caddy version:
v2.7.6
4. How I installed and ran Caddy:
a. System environment:
Docker Dekstop on Linux
b. Command:
docker compose up cdy
c. Service/unit/compose file:
services:
cdy:
image: caddy
restart: unless-stopped
ports:
- 8080:8080
# - 443:443
# - 443:443/udp
volumes:
- ./.compose/volumes/cdy/Caddyfile:/etc/caddy/Caddyfile:ro
- rls-public:/srv/public:ro
- rls-storage:/srv/private:ro
- cdy_data:/data
- cdy_config:/config
d. My complete Caddy config:
{
auto_https off
http_port 8080
log {
format console
level debug
}
}
http://localhost, http://localhost.localdomain, http://*.localhost, http://*.localhost.localdomain {
root * /srv/public
file_server
encode zstd gzip
@static file
@notStatic not file
header @static Cache-Control "public, max-age=31536000"
reverse_proxy @notStatic rls:3000 {
@error status 400 404 422 500
handle_response @error {
root * /srv/public
rewrite * /{rp.status_code}.html
status {rp.status_code}
file_server
}
}
}