1. Caddy version (caddy version
):
Caddy 2.45 built for Windows using xcaddy with replace-response and format-encoder included.
2. How I run Caddy:
Caddy runs as a Windows service set up by nssm. Configuration changes are performed using Caddy Reload.
a. System environment:
Windows Server 2019
b. Command:
nssm start Caddy (nssm starts Caddy with the "run" argument)
c. Service/unit/compose file:
n/a
d. My complete Caddyfile or JSON config:
(not complete - but you really don’t need to see a dozen perfectly working sites)
{
#debug
email pwh@cassland.org
order replace after encode
grace_period 10s
}
ai.cassland.org {
rewrite / /magnoliaPublic/ai/index.html
uri /dms/* replace /dms/ /magnoliaPublic/dms/ai/ 1
@nopublic not path /magnoliaPublic/ai/*
uri @nopublic replace / /magnoliaPublic/ai/ 1
encode gzip
replace {
`/magnoliaPublic/dms/ai/` `/dms/`
`/magnoliaPublic/ai/` `/`
}
reverse_proxy http://localhost:8080
log {
output file .\Logs\AIaccess.log
format formatted
}
}
(The back-tick quoting is there to see if it made a difference; it didn’t.)
3. The problem I’m having:
I am reverse-proxying to a site running in Tomcat using a CMS called Magnolia (in an obsolete version). For architectural reasons any site in Magnolia is not at the server root, but under “/magnoliaPublic/” (there is a corresponding “/magnoliaAuthor/” for staging development). Furthermore, I am running multiple sites in Magnolia by adding another layer, so that the site root is (in the example I’m testing) actually at “/magnoliaPublic/ai/”. (There is an alternative substitution required which needs no separate discussion.) The URLs are published without this extra path element, and it is added in the Caddyfile using uri directives - this is working perfectly.
However, Magnolia generates internal links which include these additional path elements, so I need to remove the string “/magnoliaPublic/ai” from any internal link URL returned from Magnolia.
I have already had this running successfully for several years in Caddy v1 using the directives:
filter rule {
content_type text/html.*
search_pattern /magnoliaPublic/dms/ai/
replacement /dms/
}
filter rule {
content_type text/html.*
search_pattern /magnoliaPublic/ai/
replacement /
}
However, using the Caddy 2 version in the Caddyfile above is having no effect. That’s to say, the reverse-proxying is working fine, but the responses still contain the strings which the replace directive should have removed.
The site works with the strings remaining in, but I wish to hide them from the public users as they are an unnecessary complication (and expose information about the server I prefer to keep obscure).
4. Error messages and/or full log output:
Nothing pertinent is logged.
5. What I already tried:
I haven’t tried changing anything apart from adding quotes to the strings in the replace directive, because I cannot see any error in the configuration I have created. I have found another thread in this forum in which the same problem is raised, and that thread has no useful conclusion (the last post was saying that the suggestions given did not work).
6. Links to relevant resources:
Paul