I’m just wondering whether a way of hiding services would be to present a different landing for services based on the origin of the request. Is Caddy able to distinguish between a request originating from the router port forward and from within the LAN?
If not, I wonder if, through the split-DNS arrangement, whether requests from outside the network can be forwarded to one Caddy reverse proxy with a landing page with limited service offerings, while a second Caddy reverse proxy handles all internal requests? This second Caddy instance can have a landing page with a wider range of service offerings.
The code block below assumes that static landing pages in /usr/local/www/html are being served. For the trusted network (10.1.1.0/24) the landing page will be index.html (the default). For the untrusted network (anything else!) the landing page will be untrusted.html.
That looks about right. You can reduce the matchers to a single line each by using the single-line matcher syntax (remove the { } and move the contents up to immediately beside the named matcher declaration.
You only need the “untrusted” matcher though, because the directives will be sorted with the most specific matcher first, so you can leave the opposite case as a fallback.
I’m not so sure, or I’m just not understanding (probably the latter). I just tried this, and I got index.html for both the trusted and untrusted networks.
mydomain.com {
@untrusted not remote_ip 10.1.1.0/24
root * /usr/local/www/html
file_server
file server @untrusted {
index untrusted.html
}
}
Also I think there’s some weird behaviour going on with the Caddyfile directive sorting function that I’ll need to dig into more, but if you put the fallback file_server afterwards, it seems to adapt correctly, but not if you have it first. Caddy should always sort something that has any matcher before anything that has no matcher. I’ll do a bit of digging there.
Anyways, this should work for now:
mydomain.com {
@untrusted not remote_ip 10.1.1.0/24
root * /usr/local/www/html
file_server @untrusted {
index untrusted.html
}
file_server
}
Oops. How did that happen? It was actually correct in my Caddyfile.
Freakin’ awesome
Even if there is some weird behaviour, it costs an extra line and a bit to circumvent the issue. In some ways, the slightly longer version makes it clearer to a noob like me. I’m happy with both versions.
Yeah I consider it a bug. I just added a fix to the PR I already had open to fix another unrelated sorting issue (fix for this is case is in the 2nd commit):