Routing incoming public/service to multiple internal/service

1. Caddy version (caddy version):

v2.3.0

2. How I run Caddy:

a. System environment:

Windows Server 2019

b. Command:

caddy run --watch

c. Service/unit/compose file:

Paste full file contents here.
Make sure backticks stay on their own lines,
and the post looks nice in the preview pane.

d. My complete Caddyfile or JSON config:

my.imperial.edu {  
    @stuss { path_regexp ^/StudentSelfService(/.*)?$ }
    reverse_proxy @stuss https://v5ss2.imperial.edu:8443
    @regss { path_regexp ^/StudentRegistration(/.*)?$ }
    reverse_proxy @regss https://v5ss2.imperial.edu:8444
    @finss { path_regexp ^/FinanceSelfService(/.*)?$ }
    reverse_proxy @finss https://v5ss1.imperial.edu:8443
}

3. The problem I’m having:

New to Caddy. Needing to take a single public subdomain and route to separate server:port depending upon services specified in URL.

See configuration in CaddyFile. Browser is giving a blank page for this code. How to resolve? Also, is there a debug or lower level for Caddy logging? If so, how is logging level configured?

For instance

my.imperial.edu/StudentSelfService routes to https://v5ss2.imperial.edu:8443/StudentSelfService
my.imperial.edu/StudentRegistration routes to https://v5ss2.imperial.edu:8444/StudentRegistration

4. Error messages and/or full log output:

Browser shows blank page. Not hitting

5. What I already tried:

6. Links to relevant resources:

That’s quite an old version! Please upgrade to v2.5.1.

That’s not valid matcher syntax. Don’t use braces if you only have a single matcher:

@stuss path_regexp ^/StudentSelfService(/.*)?$

Also, you probably don’t need to use path_regexp here, you can probably just use use a path matcher like /StudentSelfService*. You could write it like this:

my.imperial.edu {
	reverse_proxy /StudentSelfService* https://v5ss2.imperial.edu:8443
	reverse_proxy /StudentRegistration* https://v5ss2.imperial.edu:8444
	reverse_proxy /FinanceSelfService* https://v5ss1.imperial.edu:8443
}

If your matcher didn’t match, then your request would probably go unhandled according to this config. Caddy’s default behaviour for unhandled requests is to return a blank 200 response – because it worked as configured, you didn’t tell it to do anything else.

You can add the debug global option to set the logging level to debug, which can reveal some extra details. Put this at the top of your config:

{
	debug
}
1 Like

Thank you for quick responses. Will give those a try and get back to update.

Both methods worked. Thank you

2 Likes

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