1. Caddy version (caddy version
):
v2.2.1
2. How I run Caddy:
As a systemd service on raspbian. Caddyfile in /etc/caddy/.
a. System environment:
Raspbian 7
b. Command:
caddy run / caddy adapt / caddy reload
c. Service/unit/compose file:
N/A(?)
d. My complete Caddyfile or JSON config:
#snippet to detefine logging
(logging) {
log {
output file /var/log/access.log
}
}
#snippet to determine whether hosts are inside or outside LAN.
(ip_match) {
@lan_hosts {
remote_ip 10.10.1.1/24 {$VPNIP}
}
@not_lan_hosts {
not {
remote_ip 10.10.1.1/24 {$VPNIP}
}
}
}
#snippet to deny access to hosts from outside LAN
(access_denied) {
respond @not_lan_hosts "Access Denied" 403 {
close
}
}
########################################################################
pve.rmwhite.us {
import logging
import ip_match
import access_denied
reverse_proxy @lan_hosts {
to 10.10.1.50:8006
transport http {
tls_insecure_skip_verify
}
}
}
3. The problem I’m having:
I am working from home connected to a VPN. My desktop gets a different IP address every day, but I still need to use my local services. I would like to be able to update my primary computer’s VPN IP via a script. I am attempting to assign this VPN IP to an environment variable ($VPNIP) so I can simply update that variable, caddy reload, and have access to my local services.
The allow and deny blocks are entered as snippets in the beginning of my caddyfile.
4. Error messages and/or full log output:
If I enter the environment variable in the form {$VPNIP}, running “caddy adapt” just shows that caddy is ignoring the environment variable. That is to say, if I had:
remote_IP 10.10.1.1/24 {$VPNIP}
the caddyfile is parsed as:
[{“remote_ip”:{“ranges”:[“10.10.1.1/24,”]}}]
which ignores the environment variable, but caddy will run.
If I use the format {env.VPNIP}, I get the same output as above from caddy adapt, but caddy reload provides the error:
reload: sending configuration to instance: caddy responded with error: HTTP 400: {“error”:"loading config: loading new config: loading http app module: provision http: server srv0: setting up route handlers: route 0: loading handler modules: position 0: loading module ‘subroute’: provision http.handlers.subroute: setting up subroutes: route 0: loading matcher modules: module name ‘not’: provision http.matchers.not: loading matcher sets: module name ‘remote_ip’: provision http.matchers.remote_ip: invalid IP address: "}
and caddy will not run.
5. What I already tried:
I tried both of the environment variable formats I’ve found in the documentation.