Pattern Matching Index (simple)

1. Caddy version (caddy version): 2.4.5

2. How I run Caddy:

docker-compose up caddy (with official caddy:alpine)

a. System environment:

N/A

b. Command:

N/A

c. Service/unit/compose file:

N/A

d. My complete Caddyfile or JSON config:

fancydomain.com {
        handle / {
                rewrite * /pages/lp
                reverse_proxy nuxt:8001
        }
        handle /* {
                reverse_proxy nuxt:8001
        }
}

3. The problem Iā€™m having:

For backend reasons, I need to reverse proxy index ( https://fancydomain.com ) to /pages/lp and everything else do just reverse proxy with same path.

E.g.

/ ā†’ nuxt:8001/pages/lp (The Special case I am trying to introduce)

/xyz ā†’ nuxt:8001/xyz

/hello/world ā†’ nuxt:8001/hello/world

4. Error messages and/or full log output:

No Error messages, but it is letting

https://fancydomain.com go to nuxt:8001/ instead of https://fancydomain go to nuxt:8001/pages/lp

5. What I already tried:

If I remove the handle /* part (see below) then it works with the special case, but everything else fails.
It seems like the handle /* overrides the handle /.

fancydomain.com {
        handle / {
                rewrite * /pages/lp
                reverse_proxy nuxt:8001
        }
} 

6. Links to relevant resources:

N/A

The handle blocks here are redundant, you can just do this:

fancydomain.com {
	rewrite / /pages/lp
	reverse_proxy nuxt:8001
}

The * in rewrite is the matcher, so you can just change it to / to only match requests to the root.

1 Like

@francislavoie Thank you! I used so much time on this and I nearly pulled my non-existing hair out! :smiley:

Have an awesome week!

2 Likes

You too! Glad I could help

:grin:

2 Likes

This topic was automatically closed after 30 days. New replies are no longer allowed.