Reverse_proxy two domains combined with rewrite

1. Output of caddy version:

v2.5.1 h1:bAWwslD1jNeCzDa+jDCNwb8M3UJ2tPa8UZFFzPVmGKs=

2. How I run Caddy:

a. System environment:

Windows 2012
Microsoft Windows [Version 6.2.9200]

b. Command:

caddy_windows_amd64.exe run

c. Service/unit/compose file:

n.a.

d. My complete Caddy config:

{
#    auto_https disable_redirects
    acme_ca https://acme-staging-v02.api.letsencrypt.org/directory
}

webmail.gezondheidscentrumdesprank.nl {
        reverse_proxy 127.0.0.1:8443 
}

www.fysiotherapiedemortel.nl {
    handle_path /webmail/* {
        redir https://webmail.fysiotherapiedemortel.nl
    }
    redir /webmail /webmail/
    handle {
        reverse_proxy 127.0.0.1:81
    }
}

www.gezondheidscentrumdesprank.nl {
    handle_path /webmail/* {
        redir https://webmail.gezondheidscentrumdesprank.nl
    }
    redir /webmail /webmail/
    handle {
        reverse_proxy 127.0.0.1:81
    }
}

ftp.gezondheidscentrumdesprank.nl,
ftp.fysiotherapiedemortel.nl,
secu.fysiotherapiedemortel.nl,
vpn.fysiotherapiedemortel.nl,
xibo.fysiotherapiedemortel.nl {
    handle {
        reverse_proxy 127.0.0.1:81
    }
}

dev.fysiotherapiedemortel.nl,
dev.gezondheidscentrumdesprank.nl {
    handle {
        reverse_proxy 127.0.0.1:18081 
    }
}

3. The problem I’m having:

I would like to reverse proxy two domains to underlying servers on the same machine that is hosting caddy (i.e. apache 81 on , IIS on 18081 and kerio mailserver on 8443).

So webmail.[domain].nl needs to be proxied to 8443. dev.[domain].nl needs to be proxied to 18081, and all other subdomains need to be proxied to 81.
This part I can get working with the reverse_proxy directive.

What I furthermore would like to achieve is that when I enter www.[domain].nl/webmail, I get redirected to webmail.[domain].nl.
This seems to be working to.

And lastly, the parts which I can’t get to work, is that kerio hosts it’s file on a path /webmail. However I would lik to rewrite this to /. So that when accessing the webmail, one navigates to webmail.[domain].nl instead of webmail.[domain].nl/webmail/

And of course, all http request should be redirected to https.

Note, the underlying server all transport of non-secure port, but these do rely on the subdomain referer…

4. Error messages and/or full log output:

n.a.

5. What I already tried:

6. Links to relevant resources:

Do you want to redirect (redir) the web browser from webmail.example.nl/ to webmail.example.nl/webmail/ or

Do you want to internally rewrite and mangle the path, so for the web browser the path looks like / but the upstream web mailer receives /webmail/?

1 Like

I would like to achieve the second, so a rewrite.

You can simplify this a bit, you don’t need handle in this case:

www.fysiotherapiedemortel.nl {
	redir /webmail* https://webmail.fysiotherapiedemortel.nl
	reverse_proxy 127.0.0.1:81
}

So what you want is this, I think:

dev.fysiotherapiedemortel.nl,
dev.gezondheidscentrumdesprank.nl {
	rewrite * /webmail{uri}
	reverse_proxy 127.0.0.1:18081 
}
1 Like

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