1. Caddy version (caddy version
):
2.0.0
2. How I run Caddy:
a. System environment:
Ubuntu 18.04 with systemd 237
b. Command:
systemctl start caddy
c. Service/unit/compose file:
The same as provided in the documentation.
d. My complete Caddyfile or JSON config:
localtest.com {
rewrite /A/* /B/*
route /B/* {
root * /mnt/Data/projects/frontends/B
file_server
}
reverse_proxy /api/* 127.0.0.1:8080
}
3. The problem I’m having:
What I’m trying to do is to serve the files (some HTML files) in root
, but by using the path prefix /A/
instead of the actual directory name B
. Also I don’t want to expose /B/
to the outside world.
Basically this is to provide consistent path prefix, since the directory name (B
) might change in the future, but I don’t want the path to change for my clients. Also this prevent users from knowing the actually directory name.
But I’m always getting 404 response, caddy seems to think the files does not exist.
This used to be working with Caddy V1 with a little hack: Mark /B/
as internal, and respond with X-Accel-Redirect
header:
localtest.com {
root /mnt/Data/projects/frontends
internal /B/
proxy /A/ 127.0.0.1:8080 { transparent }
# Here: 1. the backend respond with `X-Accel-Redirect: /B/my_file.html`, and
# 2. caddy intercepts this header, serving `/mnt/Data/projects/frontends/B/my_file.html` to the client.
reverse_proxy /api/* 127.0.0.1:8080
}