Placeholder variable for local server's IP address

1. Caddy version (caddy version):

v2.5.1 h1:bAWwslD1jNeCzDa+jDCNwb8M3UJ2tPa8UZFFzPVmGKs=

2. How I run Caddy:

n/a (but I just use the one from the Caddy Debian repo)

a. System environment:

Debian 10

b. Command:

# caddy run --watch
2022/07/07 21:15:20.243 INFO    using adjacent Caddyfile 

c. Service/unit/compose file:

n/a (but I just use the one from the Caddy Debian repo)

d. My complete Caddyfile or JSON config:

cloud-test.internal.1904.tech:80 {
        reverse_proxy {
                to http://nc-node02.colo.1904.tech:80

                lb_policy first

                header_down "X-Served-By" "Edge05"

                header_up "X-Forwarded-By-Host" {system.hostname}

                flush_interval -1

                health_uri /ping
                health_port 81
                health_interval 60s
                health_timeout 10s
                health_status 200
        }

        handle_errors {
                rewrite * /{http.error.status_code}
                respond "The site you are attempting to connect to is currently unavailable" 504
        }

}

3. The problem I’m having:

When using Caddy as a reverse proxy, Caddy sends the usual headers to the upstream server:

X-Forwarded-Proto => http
X-Forwarded-Host => cloud-test.internal.1904.tech
X-Forwarded-For => 165.225.216.149

I am looking to provide a few additional headers to the upstream server, mostly for diagnostics/troubleshooting and to tidy up the upstream’s access logs.

X-Forwarded-By => 10.245.199.105
X-Forwarded-By-Host => DMZ-Edge05

I can get the hostname via {system.hostname} but I don’t see any IP-related stuff in Replacer.go#L280.

Is there a good option to get the local IP address of the Caddy server to put into a header?

4. Error messages and/or full log output:

5. What I already tried:

6. Links to relevant resources:

You could grab that info ahead of time with a shell script, then pass it to Caddy as an environment variable. I don’t think this is something you’ll get dynamically from Caddy.

You can set environment variables via systemd config overrides:

Then use them in your Caddyfile:

Which local IP address? There are usually several interfaces.

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