wenkechen
(Wenke Chen)
June 29, 2023, 3:42pm
1
1. The problem I’m having:
I have some API servers behind a entry server.
eg: api1:8080
, api2:8080
, api3:8080
…
There is a entry API server: api.demo.com
I want to foward request to different server by sub dir, eg:
https://api.demo.com/api1/api/v1/foo => api1:8080/api/v1/foo
https://api.demo.com/api2/api/v1/foo => api2:8080/api/v1/foo
https://api.demo.com/api3/api/v1/foo => api3:8080/api/v1/foo
…
But the following configuration doesn’t work
2. Error messages and/or full log output:
PASTE OVER THIS, BETWEEN THE ``` LINES.
Please use the preview pane to ensure it looks nice.
3. Caddy version:
2.6
4. How I installed and ran Caddy:
a. System environment:
b. Command:
PASTE OVER THIS, BETWEEN THE ``` LINES.
Please use the preview pane to ensure it looks nice.
c. Service/unit/compose file:
PASTE OVER THIS, BETWEEN THE ``` LINES.
Please use the preview pane to ensure it looks nice.
d. My complete Caddy config:
api.demo.com {
log {
output file /var/log/api.access.log
}
@backend {
path_regexp backend ^/([^/]+)/(.+)
}
handle_path /{re.backend.1}/* {
reverse_proxy {re.backend.1}:8080
}
}
PASTE OVER THIS, BETWEEN THE ``` LINES.
Please use the preview pane to ensure it looks nice.
5. Links to relevant resources:
matt
(Matt Holt)
June 29, 2023, 5:53pm
2
Try this: handle_path @backend {
wenkechen
(Wenke Chen)
June 30, 2023, 4:15am
3
{"level":"info","ts":1688098398.0698562,"msg":"using provided configuration","config_file":"/etc/caddy/Caddyfile","config_adapter":"caddyfile"}
Error: adapting config using caddyfile: parsing caddyfile tokens for 'handle_path': /etc/caddy/Caddyfile:29 - Error during parsing: path matcher must begin with '/', got @backend
I changed it to handle_path /@backend {
, still not work
matt
(Matt Holt)
June 30, 2023, 5:50am
4
That’s not what I typed Double check that
You can’t use handle_path
in that case, it only supports simple path matchers. It’s a shortcut for handle
+ uri strip_prefix
so it doesn’t support all matchers.
You can use the long form instead like this:
@backend path_regexp backend ^/([^/]+)/(.+)
handle @backend {
uri strip_prefix /{re.backend.1}
reverse_proxy {re.backend.1}:8080
}
1 Like
wenkechen
(Wenke Chen)
June 30, 2023, 6:41am
6
Thank you a lot !!!
This problem has bothered me for many days
2 Likes
matt
(Matt Holt)
June 30, 2023, 6:49am
7
Oh, oops. I totally forgot about that. Thanks Francis
1 Like
system
(system)
Closed
July 30, 2023, 6:50am
8
This topic was automatically closed 30 days after the last reply. New replies are no longer allowed.