1. Caddy version (caddy version
):
v2.0.0 h1:pQSaIJGFluFvu8KDGDODV8u4/QRED/OPyIR+MWYYse8=
2. How I run Caddy:
I’m running caddy via docker (from caddyserver/caddy-docker):
a. System environment:
caddyserver/caddy-docker Docker container on Mac OSX host (Catalina) with Docker Desktop
b. Command:
docker run -d -p 80:80 -p 443:443 -p 2019:2019 -v /Users/scott/caddy/index.html:/usr/share/caddy/index.html -v caddy_data:/data -v $PWD/Caddyfile:/etc/caddy/Caddyfile --name caddy caddy
c. Service/unit/compose file:
I’m running the default Docker configuration from caddyserver/caddy-docker using the instructions from here: Docker Hub
d. My complete Caddyfile or JSON config:
{
admin 0.0.0.0:2019
}
local.dev-example.net {
tls internal
@siteredirect {
path_regexp siteredirect_regexp ^/site-redirect?target=/?(.*)
}
rewrite @siteredirect /{http.regexp.siteredirect_regexp.1}
reverse_proxy tcp/localhost:5678
}
3. The problem I’m having:
I’m attempting to translate an nginx configuration over to caddy. I have the following nginx rewrite rule:
# Site Redirect
location ~* /site-redirect(.*) {
set $target $arg_target;
# Add a leading slash if $target doesn't have one
if ($target ~* ^(?!\/)(.*)) {
set $target "/$1";
}
rewrite ^ $target? redirect;
}
This rewrite rule will rewrite traffic from:
https://www.dev-example.net/site-redirect?target=billing
to https://www.dev-example.net/billing
,
and
https://www.dev-example.net/site-redirect?target=/billing
to https://www.dev-example.net/billing
,
I’m very much aware that the snippet above won’t work due to the fact that the path_regexp only looks at the path and does not include the query string, but I’m unable to piece together a way to get a specific value out of the query string and perform the rewrite using it.
Is there a way to do this with Caddy v2?
4. Error messages and/or full log output:
I’m not getting an error message. The URL isn’t getting rewritten.
5. What I already tried:
I have been reading through the Caddy v2 documentation. Path_regexp matchers don’t include query string parameters. The expression matchers, per the documentation, must resolve to a true/false value. I’ve looked through the example Caddyfiles on the github repo. My google-fu is failing me as well.