Reverse proxy is not working for domain name on Windows

1. The problem I’m having:

The reverse proxy works from one port to another on localhost. However, it is not working for domain name (bar.company.local) as defined in the caddy file.

2. Error messages and/or full log output:

The output for command (curl -k https://bar.company.local) is an empty line as shown below. I was expecting to see:
Goodbye, world! (foo.company.local)

C:\Users\rrudra>curl -k https://localhost:2017
Goodbye, world! (localhost:2017)
C:\Users\rrudra>curl -k https://localhost:2016
Goodbye, world! (localhost:2017)
C:\Users\rrudra>curl -k https://foo.company.local
Goodbye, world! (foo.company.local)
C:\Users\rrudra>curl -k https://bar.company.local

3. Caddy version:

v2.7.3 (on Windows)

4. How I installed and ran Caddy:

choco install caddy

a. System environment:

Windows 11 Enterprise (Version 21H2) (OS Build 22000.2538)

b. Command:

caddy run

d. My complete Caddy config:

localhost:2017 {
	respond "Goodbye, world! (localhost:2017)"
}

localhost:2016 {
	reverse_proxy https://localhost:2017
}

foo.company.local {
	respond "Goodbye, world! (foo.company.local)"
}

bar.company.local {
	reverse_proxy https://localhost:2017
}

Windows host file entries:

127.0.0.1 foo.company.local
127.0.0.1 bar.company.local

5. Links to relevant resources:

None

The problem is the Host header. It gets preserved by the proxy, so effectively the proxy request has bar.company.local in it (with port 2017) so Caddy drops the request because it wasn’t configured to respond to bar.company.local:2017.

See reverse_proxy (Caddyfile directive) — Caddy Documentation for the solution.

The following change to the CaddyFile did the trick. Thank you!

bar.company.local {
	reverse_proxy https://localhost:2017 {
        header_up Host {upstream_hostport}
    }
}
1 Like

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