1. The problem I’m having:
I’m trying to use expression matching to deny access to certain sub directories. The expression matching work as expected, however I’d like to add the variable http.request.host to a path but this value needs concatenating to make the complete path.
The hardcoded version is shown here:
@block {
expression `path("/client/*") && ! path("/client/THESITE.COM/*")`
}
respond @block 404
I’d like the replace the parts in CAPS above using the following pseudo code:
@block {
expression `path("/client/*") && ! path("/client/{http.request.host}/*")`
}
respond @block 404
So that with multiple sites I don’t have to edit this value manually.
I can’t seem to find any documentation about how to achieve this. The variable http.request.host is correct, but I’m not sure about the syntax for the 2nd path
2. Error messages and/or full log output:
Not really relevant as I don’t know the syntax
3. Caddy version:
V2.6.4
4. How I installed and ran Caddy:
Installed on Linux via apt install caddy running under systemd
a. System environment:
Ubuntu 22.04
b. Command:
c. Service/unit/compose file:
d. My complete Caddy config:
# The Caddyfile is an easy way to configure your Caddy web server.
#
# Unless the file starts with a global options block, the first
# uncommented line is always the address of your site.
#
# To use your own domain name (with automatic HTTPS), first make
# sure your domain's A/AAAA DNS records are properly pointed to
# this machine's public IP, then replace ":80" below with your
# domain name.
{
http_port 80
https_port 443
}
# Pull out to make each site as simple as possbile
(websockets) {
@websockets {
header Connection Upgrade
header Upgrade websocket
}
}
eyeronic.duckdns.org:443 {
root * /mnt/c/source/eyeronic_iss/trunk/www
import websockets
route /socket {
reverse_proxy @websockets 127.0.0.1:8089
}
@block {
expression `path("/client/*") && ! path("/{{http.request.host}}/*")`
}
respond @block {http.request.host}
file_server
tls internal
php_fastcgi unix//var/run/php/php8.1-fpm.sock
}
5. Links to relevant resources:
This might be relevant but not sure: