How to reverse to https with http

1. Caddy version (caddy version):

caddy 2

2. How I run Caddy:

systemctl start caddy

a. System environment:

ubuntu 18.04

b. Command:

Paste command here.

c. Service/unit/compose file:

Paste full file contents here.
Make sure backticks stay on their own lines,
and the post looks nice in the preview pane.

d. My complete Caddyfile or JSON config:

:45000 {
        handle /* {
                root * /home/mywork/CgsBim

        handle /api/* {

        handle_path /bimface/api/* {
                reverse_proxy {
                        header_up X-Forwarded-Proto https


3. The problem I’m having:

When I POST in my code, It returned an 302 to an http url. But the real api address is , and I dont know why it redirect to an http address that seems not exists.

4. Error messages and/or full log output:

5. What I already tried:

So I add "header_up X-Forwarded-Proto https " , to reverse_proxy, but still got 302 result.
And I tried the https address with postman, This address works fine.

6. Links to relevant resources:

You need to make sure that the Host header is correctly set. By default, Caddy passes through the Host header from the original request.

You can solve this by using a placeholder which takes the value of the currently selected upstream:

reverse_proxy {
	header_up Host {http.reverse_proxy.upstream.hostport}

You can simplify this by removing the matcher altogether:

handle {

The difference is that with the matcher specified, Caddy will have to make a comparison against the request path on each request, which will always match (because the path always starts with /). Omitting it avoids that redundant check.


This Solved perfectly.

But handle / not work , It just result to a blank page. Not my index.html, and can’t find the real reason.
I will retry this later.

Thanks for your help.

1 Like

Don’t use /, just remove the matcher altogether. Use handle {.

Using / will only match requests to / exactly. Omitting it will match all requests.

1 Like

Yes, This config works well.
Thanks agian.

1 Like

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