Can't remember where I found the info for this snippet

(proxyheaders) {
  flush_interval -1
  header_up Host {host}
  header_up X-Real-IP {http.request.header.CF-Connecting-IP}
  header_up X-Forwarded-For {http.request.header.CF-Connecting-IP}
  header_up X-Forwarded-Proto {scheme}
  header_up X-Forwarded-Host {hostpost}
  header_up X-Forwarded-Ssl {on}
}

I know I got the values that go inside {} came from somewhere, but I can’t recall where. I was sure this was on the Caddy docs somewhere, but I can’t find it.

  header_up X-Forwarded-Host {hostpost}

This one looks like it’s probably wrong…which is why I was trying to find this info again.

Caddy’s placeholders are a bit fragmented in the documentation, because each execution context may set its own placeholders. Not all placeholders are always available.

Here’s a list of all the HTTP placeholders:

Here’s a list of the Caddyfile placeholder shortcuts (exclusive to the Caddyfile):

Pretty certain {on} does not exist as a placeholder in Caddy.

2 Likes

To add to this, you also do not need the header_up X-Forwarded-Proto {scheme} line. You should be getting a warning for having that because it’s already set for you.

1 Like

Good to know.

Thank you! Looks like what I recall. Time to actually bookmark them this time… :slight_smile:

Looks like not…just copied from nginx along time ago, I guess. Wonder what the equivalent is or if it’s even needed at all. :upside_down_face:


Interesting. Never seen any errors or warnings specifically relevant to it. Currently on v2.3.0 h1:fnrqJLa3G5vfxcxmOH/+kJOcunPLhSBnjgIvjXV/QTA=.

I’ll remove it (and anything else!) that’s superfluous, though. Less stuff = more good. :slight_smile:

Yeah I just realized this is a typo. It’s {hostport} (port, not post).

Also…

This one isn’t useful either, this is already the default behaviour of Caddy.

2 Likes

That’s what I assumed which is what brought me to making this question/post to begin with haha – darn typos! That’ll teach me to not copy and paste… :upside_down_face:

Also: thanks for another useful link. :smiley:


Edit: I think it’s simplified to just this now, then:

(proxyheaders) {
  flush_interval -1
  header_up X-Real-IP {http.request.header.CF-Connecting-IP}
  header_up X-Forwarded-For {http.request.header.CF-Connecting-IP}
  header_up X-Forwarded-Host {hostport}
}
1 Like

Technically the default behavior of Caddy’s proxy is to pass the Host header unchanged to the upstream. The {host} placeholder is just the hostname portion, omitting port if any. Slightly different, but only sometimes.

1 Like

I’m learning so much today; thank y’all! :grinning_face_with_smiling_eyes:

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