1. The problem I’m having:
I am trying to setup a caddy reverse proxy that routes requests to other machines. I have 2 EC2 (Machine A, Machine B) instances with public IPs. I launched Caddy and have the following reverse proxy configs.
Machine A (52.87.249.192)
{
debug
on_demand_tls {
ask http://127.0.0.1:9123
# every 2 min we can sign 5 certificates
burst 5
interval 2m
}
}
:443 {
reverse_proxy localhost:8000
tls {
on_demand
}
}
:80 {
reverse_proxy http://3.235.124.246
}
Machine B (3.235.124.246)
{
debug
on_demand_tls {
ask http://127.0.0.1:9123
# every 2 min we can sign 5 certificates
burst 5
interval 2m
}
}
http://3.235.124.246:80 {
reverse_proxy localhost:9000
respond /caddy-health-check 200 {
body "Caddy http reverse proxy running!
"
}
}
If I run
curl -v http://52.87.249.192/<anything I want here>
on my local machine, I always get a 200 response with no content. But on the Caddy logs on Machine B or the server listening to port 9000 on Machine B, I don’t see anything.
If I run
curl -v http://3.235.124.246/caddy-health-check
on my local machine or on Machine A, I get back the expected “Caddy http reverse proxy running!” response.
If I run
curl -v http://3.235.124.246/<anything I want here>
on either my local machine or Machine A, I see the request on both Caddy logs and the server listening to 9000 on Machine B.
What I would like to do is to be able to send any request from my local machine to Machine A and forward the exact request to Machine B and then have the response sent back to my local machine.
Any help would be appreciated. Thanks!
2. Error messages and/or full log output:
I don’t actually have error messages.
On Machine A, whenever I make a request the Caddy logs prints this:
2024/07/02 17:50:00.231 DEBUG http.handlers.reverse_proxy selected upstream {"dial": "3.235.124.246:80", "total_upstreams": 1}
2024/07/02 17:50:00.236 DEBUG http.handlers.reverse_proxy upstream roundtrip {"upstream": "3.235.124.246:80", "duration": 0.004377609, "request": {"remote_ip": "143.58.200.28", "remote_port": "55204", "client_ip": "143.58.200.28", "proto": "HTTP/1.1", "method": "GET", "host": "52.87.249.192", "uri": "/caddyajlfk", "headers": {"User-Agent": ["curl/8.4.0"], "Accept": ["*/*"], "X-Forwarded-For": ["143.58.200.28"], "X-Forwarded-Proto": ["http"], "X-Forwarded-Host": ["52.87.249.192"]}}, "headers": {"Server": ["Caddy"], "Date": ["Tue, 02 Jul 2024 17:50:00 GMT"], "Content-Length": ["0"]}, "status": 200}
But anything going through the reverse proxy on Machine A does not show up on logs on Machine B.
3. Caddy version:
v2.8.4
4. How I installed and ran Caddy:
a. System environment:
I installed go and xcaddy through a nix flake and then built caddy with
xcaddy build --with github.com/caddy-dns/godaddy
Although technically I no longer need the godaddy version.
b. Command:
I start caddy by running
caddy start --config Caddyfile
c. Service/unit/compose file:
d. My complete Caddy config:
I pasted both my caddy configs in the question above.