1. The problem I’m having:
I’m trying to convert an nginx config with an X-Accel-Redirect mechanism for thumbnails. The idea is that the back end only gets involved when requesting an image thumbnail for the first time, at which point it writes to a static image folder (future requests will hit that), and also returns the generated file via the X-Accel-Redirect mechanism. I’m running Caddy 2.10.2 (which I note is over 6 months old, though still the latest release).
I gather that handle_response can’t be used as it doesn’t replace the request properly like nginx does, and the caddy docs say that I should use intercept, but I can’t make the syntax work.
I’m basing it on the example from intercept (Caddyfile directive) — Caddy Documentation
I’m wondering if I have got the syntax correct, but perhaps intercept is not in the 2.10.2 build?
2. Error messages and/or full log output:
When I try to enable this config, it fails with this error:
Error: adapting config using caddyfile: parsing caddyfile tokens for 'handle': parsing caddyfile tokens for 'handle': parsing caddyfile tokens for 'reverse_proxy': unrecognized subdirective intercept
3. Caddy version:
v2.10.2 h1:g/gTYjGMD0dec+UgMw8SnfmJ3I9+M2TdvoRL/Ovu6U8=
4. How I installed and ran Caddy:
From stock Ubuntu packages, as per docs.
a. System environment:
Ubuntu 22.04 on aarch64.
b. Command:
c. Service/unit/compose file:
Default from stock package
d. My complete Caddy config:
api.chamsocial.com {
# Compression
encode gzip zstd
# Limit upload/request body size
request_body {
max_size 4GB
}
# Access log (file)
log {
output file /var/log/caddy/api.chamsocial.access.log
}
# Security headers
header {
Alt-Svc "h3=\":443\"; ma=86400"
Strict-Transport-Security "max-age=63072000; includeSubDomains; preload"
X-Frame-Options "SAMEORIGIN"
X-Content-Type-Options "nosniff"
X-XSS-Protection "1; mode=block"
Referrer-Policy "strict-origin-when-cross-origin"
Permissions-Policy "midi=(), microphone=(), camera=(), magnetometer=(), gyroscope=(), accelerometer=(), fullscreen=(self), payment=(), geolocation=(), usb=(), encrypted-media=()"
}
root * /var/www/www.chamsocial.com/public
# /thumb: serve from chamsocial-images if file exists, otherwise proxy to backend
handle /thumb/* {
root * /var/www/chamsocial-images
@thumbfile file
handle @thumbfile {
# Serve static thumb images
file_server
}
# Fallback to backend with X-Accel-Redirect support
handle {
reverse_proxy http://localhost:7440 {
header_up X-Real-IP {remote}
header_up Host {host}
header_up X-NginX-Proxy 1
transport http {
versions 1.1
}
@accel header X-Accel-Redirect *
intercept @accel {
rewrite {http.response.header.X-Accel-Redirect}
root * /var/www/chamsocial-images
file_server
}
}
}
}
}