How can I set X-Forwarded-Proto https using the json config API?

I’m not posting a bunch of config files, but only because everything works fine. I have no errors, I just don’t think the docs for this exist yet.

1. Caddy version (caddy version):

2.2.1

2. How I run Caddy:

A service on the digital ocean marketplace droplet template. I use the admin api to create and manage reverse proxies just fine.

a. System environment:

Ubuntu 18, running as a service (the one that’s installed on the digital ocean marketplace droplet)

b. Command:

I don’t, I use the service that starts itself. It uses the resume feature.

c. Service/unit/compose file:

This all works fine, I’ll post it later if needed.

d. My complete Caddyfile or JSON config:

Here’s an example of what I send to the admin API (anything in #{} is replaced with a value by my app, works fine as is):

{
            "@id": "vhost_#{vhost.id}",
            "match": [
              {
                "host": [
                  "#{vhost.incoming_address}"
                ]
              }
            ],
            "handle": [
              {
                "handler": "subroute",
                "routes": [
                  {
                    "handle": [
                      {
                        "handler": "reverse_proxy",
                        
                        "upstreams": [
                          {
                            "dial": "#{vhost.target_address}:#{port}"
                          }
                        ]
                      }
                    ]
                  }
                ]
              }
            ],
            "terminal": true
          }

3. The problem I’m having:

I just want to know how to format my json request to add a X-Forwarded-Proto https header, so that my backend app knows and doesn’t try to redirect.

4. Error messages and/or full log output:

No errors

5. What I already tried:

I haven’t tried anything yet because I can’t find any docs on how to format this. I could do it with directives in a caddyfile, but my use case requires the admin API. The docs are just missing this info.

6. Links to relevant resources:

None, can’t find any docs.

Not missing, unless I am totally misunderstanding your question.

You can do so with the headers property: Modules - Caddy Documentation

But note that X-Forwarded-Proto is one of the (few) hop-by-hop headers set for you already:

X-Forwarded-For and X-Forwarded-Proto are also set implicitly

1 Like

Also you could start from a Caddyfile to see how it would look in JSON:

:80
reverse_proxy localhost:8080 {
	header_up X-Forwarded-Proto https
}

Then run caddy adapt on that, and you’ll see what you need to add to your JSON reverse_proxy handler.

Ah, sorry about that then, my mistake. I’d been expecting to find that under the json config docs or the API docs.

No worries. But, to clarify, it IS in the JSON docs… (that is what I linked to)

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