Reverse Proxy for two docker containers. One on a specific port

1. Caddy version (caddy version):

v2.4.6

2. How I run Caddy:

systemctl start caddy with /etc/caddy/Caddyfile
Docker version 20.10.14, build a22408

d. My complete Caddyfile or JSON config:

mydomain {
  reverse_proxy 127.0.0.1:3000
  # NOT WORKING
  handle :3001 {
    reverse_proxy ipaddress:3001
  }
}

I also tried with:

mydomain {
  reverse_proxy 127.0.0.1:3000
  # NOT WORKING
  handle :3001 {
    reverse_proxy ipaddress:3001
  }
}

mydomain:3001 {
  reverse_proxy 127.0.0.1:3001
}

Which gives me this error:
Error code: SSL_ERROR_RX_RECORD_TOO_LONG

3. The problem I’m having:

I’d like to run a dynamic website on port 80 and it’s CMS on port 3001.
So I have the website on: mydomain
CMS on mydomain:3001
Something like the config file shown above.

5. What I already tried:

Searching the forum and finding solutions for sub dirs handles. Which is not what I’d like to have.

handle :3001 is not valid syntax. See the docs for request matching:

Also, using a domain as your site address will have Caddy only listen on ports 80 and 443 (80 for HTTP->HTTPS redirects, and 443 for your actual HTTPS traffic).

To listen on another port, then you should make another site block (as you did in your 2nd example) with the port number.

But really, you probably should use a subdomain in this situation, instead of proxying based on a port number.

For example, use cms.example.com for your CMS:

example.com {
	reverse_proxy 127.0.0.1:3000
}

cms.example.com {
	reverse_proxy 127.0.0.1:3001
}

Make sure your DNS is configured correctly to route that subdomain to your server running Caddy as well.

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