I have a Caddy 2 instance that runs in front of an architecture. This works very well.
By default, each response includes two server headers due to the different proxies the response goes through:
server: Caddy
server: Google Frontend
The issue I have is with header manipulation. I would like to remove all server headers and set a single custom server header value when the response is returned by Caddy. For instance:
server: My Custom Value
I tried different syntaxes but it seems that I can only remove all or add one.
For instance, this syntax is removing all server headers but not adding the custom one:
header {
-server
+server "My Custom Value"
}
It seems also that find/replace is not working. The following has no effect:
header {
server "Google Frontend" "My Custom Value"
}
This happens with Caddy 2.3.0.
I guess something is wrong with the syntax I use or maybe this use case is not supported? Looking at the docs I cannot understand what’s wrong. Any ideas?
@matt Thanks for your help. Unfortunately, no. When I do that, I end up with the following as response headers:
server: My Custom Value
server: Google Frontend
However, following your comment I got what the problem is. My Caddy setup also makes use of a reverse_proxy directive. Since the header server: Google Frontend comes from the reverse proxy call, I need to configure this header deletion using the reverse_proxy block. Here is the working configuration:
:443 {
header server "My Custom Value"
reserve_proxy https://example.com {
header_down -server
}
}