ReverseProxy to local Backend - Connection refused

1. Caddy version (caddy version): Caddy V2.1.1

2. How I run Caddy:

I am running cadddy from a Docker container, this is my build file:
'FROM caddy/caddy:2.1.1-alpine

ENV CONFIG_DIR /etc/caddy
ENV DATA_DIR /usr/share/caddy
COPY Caddyfile $CONFIG_DIR/Caddyfile
COPY index.html /usr/share/caddy/index.html'

and this is the command I am using to run it:
docker run -d --name="caddy" -p 2019:2019 -p 2015:2015 caddy:1.0

a. System environment:

I am running on Windows 10, Docker Desktiop

b. Command:

Caddy gets started automatically with the launch fof the docker container

c. Service/unit/compose file:

See above.

d. My complete Caddyfile or JSON config:

:2015 { 
	reverse_proxy localhost:8080

3. The problem I’m having:

I am all new to Caddy and I was simply tryin gthe most basic revese proxey setup following the Documentation given on the Caddy Site and on the Github repo site:

The backend app that I am reverse-proxying to is running on localhost:8080. It is a payara webap server with a J2EE app in a context called dashboard.
The standalone URL for the app is http://localhost:8080/dashboard/login.xhtml
When I now try to reach his URL through Caddy, I point my browser to http://localhost:2015/dashboard/index.html assuming that the redirect from Caddy will resolve this to the roper (standalone, see above) URL.

It is not happening, instead I get the following Error.

4. Error messages and/or full log output:

{“level”:“error”,“ts”:1606145180.5917492,“logger”:“http.log.error”,“msg”:“dial tcp connect: connection refused”,“request”:{“method”:“GET”,“uri”:"/dashboard/login.xhtml",“proto”:“HTTP/1.1”,“remote_addr”:“”,“host”:“localhost:2015”,“headers”:{“Cache-Control”:[“max-age=0”],“User-Agent”:[“Mozilla/5.0 (Windows NT 10.0; Win64; x64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/87.0.4280.66 Safari/537.36”],“Accept”:[“text/html,application/xhtml+xml,application/xml;q=0.9,image/avif,image/webp,image/apng,/;q=0.8,application/signed-exchange;v=b3;q=0.9”],“Sec-Fetch-Site”:[“none”],“Sec-Fetch-User”:["?1"],“Cookie”:[“JSESSIONID=55a3bb1e303291b68d1025bcbc78; JSESSIONID=583ef41f3383351a4a14dacd7ac1”],“Connection”:[“keep-alive”],“Upgrade-Insecure-Requests”:[“1”],“Sec-Fetch-Mode”:[“navigate”],“Sec-Fetch-Dest”:[“document”],“Accept-Encoding”:[“gzip, deflate, br”],“Accept-Language”:[“de-DE,de;q=0.9,en-US;q=0.8,en;q=0.7”]}},“duration”:0.0003584,“status”:502,“err_id”:“a2wcuz85x”,“err_trace”:“reverseproxy.(*Handler).ServeHTTP (reverseproxy.go:411)”}

5. What I already tried:

  • I made sure that the backend service is up and running.
  • I tried to put the Caddy container and the Payara Web App in two different containers into a docker-compose setup (this is closed to what I want to deploy ultimately). There, I am getting the exact same error message like above.

6. Links to relevant resources:

localhost inside of the container will refer to the Caddy container itself. This won’t work because your service isn’t running in the same container.

If your service is in another container, you should use the container name of that service instead of localhost.

Many thanks, that was spot on. So I changed my Caddyfile to this:
:2015 {
reverse_proxy dashboard.realWolrld_URL:8080
and it is working fine.

when I then changed it to
:80 {
reverse_proxy dashboard.realWolrld_URL:8080
it is not working any longer (changed the Docker startup script to expose port 80 as well).
Is there anything special about port 80?
Best Regards, Kai

What does this mean exactly? What are the symptoms? What happens if you use curl -v to make a request? What’s in your logs?

ok…i figured it out…I had to adopt the docker run command as well, there, port 80 was not exposed.

1 Like

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