Caddy reverse_proxy is unable to find a local network

1. The problem I’m having:

I’m trying to reverse proxy an API with Caddy. The API is running in a docker container, Caddy is not. When I call localhost:1339/eval on the same machine (outside the container) it works as expected, even when I expose the port in my server’s firewall, I am able to call it from another machine. The issue is that Caddy can’t find it when I use reverse_proxy * localhost:1339/eval which gives me a 502 when I try to call it from another machine

2. Error messages and/or full log output:

{"level":"error","ts":1689662014.7019417,"logger":"http.log.error","msg":"dial localhost:1339: unknown network localhost:1339","request":{"remote_ip":"my ip address is here","remote_port":"65204","proto":"HTTP/1.1","method":"POST","host":"eval.occluder.space","uri":"/","headers":{"Authorization":[],"User-Agent":["PostmanRuntime/7.32.3"],"Accept":["*/*"],"Connection":["keep-alive"],"Content-Type":["text/plain"],"Postman-Token":["02711f75-6074-4ae2-9297-f3d48057d143"],"Accept-Encoding":["gzip, deflate, br"],"Content-Length":["19"]},"tls":{"resumed":false,"version":772,"cipher_suite":4865,"proto":"","server_name":"eval.occluder.space"}},"duration":1.273239821,"status":502,"err_id":"k4x3vt1hx","err_trace":"reverseproxy.statusError (reverseproxy.go:1299)"}

3. Caddy version:

v2.6.4

4. How I installed and ran Caddy:

I followed this line by line.

a. System environment:

Ubuntu 20.04
Architecture: x86_64

b. Command:

For reference, this is what I’m hosting: GitHub - discord-csharp/CSharpRepl: CSharpRepl is a web api for C# REPL using the Roslyn Scripting APIs

docker run -d --user www-data --restart=always --read-only --tmpfs /tmp --tmpfs /var --memory 500M --cpus 2 -p 1339:1339-e ASPNETCORE_URLS=http://+:1339 ghcr.io/discord-csharp/csharprepl:latest
docker ps
curl -X POST -H 'Content-Type: text/plain' -d 'var c = "xD -> c"; c' localhost:1339/eval
> {"returnValue":"xD -> c","returnTypeName":"string","exception":null,"exceptionType":null,"code":"var c = \"xD -> c\"; c","consoleOut":"","executionTime":"00:00:00.0514555","compileTime":"00:00:00.5248816"}

c. Service/unit/compose file:

see command above

d. My complete Caddy config:

eval.occluder.space {
	file_server
	basicauth * {
		// auth
	}
	reverse_proxy * localhost:1339/eval
}

I have few other reverse proxy’d APIs running in the same way (not with docker, however), and they work fine

5. Links to relevant resources:

You can’t use a URL path in a proxy upstream address. It must be a hostname + port only. See the docs:

1 Like

Thank you so much

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