Reverse Proxy to internal service with port range

1. Caddy version (caddy version):

v2.3.0 (inside docker)

2. How I run Caddy:

I run caddy in a docker container with the relevant caddyfile configuration file. Then use docker-compose for minor changes.

a. System environment:

Ubuntu 20.04.2 LTS

b. Command:

Docker-compose up -d

c. Service/unit/compose file:

version: '3.8'

    container_name: PROXY-CADDY
    restart: always
      - 80:80
      - 443:443
    image: caddy:2.3.0
      - ./caddy/data:/data
      - ./caddy/config/Caddyfile:/etc/caddy/Caddyfile

d. My complete Caddyfile or JSON config:  { 


3. The problem I’m having:

I am unable to route multiple internal ports via 443 to a single service on ports 8001 and 8002 (both a required to function)

I am able to connect to the remote server using IP and tradition connection of 8001 and 8002, however this is unsecure. I would like to route communication over 443 HTTPS. via a seperate server handling all the proxy to a a single internal host.

4. Error messages and/or full log output:

No specific error messages, I can see via TCP viewer that a connection is being established when i route a single port only ( however i cannot seem to work out from Caddy documentation how to route a port range/multiple.

5. What I already tried:

As above, TCP viewer on both client and server side shows a single est connection. Is it possible to route all traffic matching a domain name over 433 to internally route any source port address to the internal server (could be anything) 8001-8005 as an example.

6. Links to relevant resources:

Reading over the documentation it does not seem to support this function or option is not available (forgive my limited networking experience on this)

Actually, this is supported. The reverse proxy docs link to this page, which shows the syntax:

This should work:


Thank you francisavoie! my mistake for missing that page.

I put in your suggestion, however it is now spitting out errors, saying the “dial address must represent precisely one socket”

PROXY-CADDY | {“level”:“error”,“ts”:1617055681.310346,“logger”:“http.log.error”,“msg”:“making dial info: upstream dial address must represent precisely one socket: represents 7”,“request”:{“remote_addr”:“117.x.x.x:19312”,“proto”:“HTTP/1.1”,“method”:“GET”,“host”:“”,“uri”:"/api/server/root-certificate-public-key",“headers”:{“X-Connectionguid”:[“2ed456e6-8156-4c58-be6f-e0580273a708”],“X-Auth”:[""],“Accept”:[“application/json”]},“tls”:{“resumed”:false,“version”:771,“cipher_suite”:49196,“proto”:"",“proto_mutual”:true,“server_name”:“”}},“duration”:0.000050938,“status”:502,“err_id”:“4ehsyrsy7”,“err_trace”:“reverseproxy.statusError (reverseproxy.go:783)”}

Any thoughts?


Hmm, my bad then. In that case, you’ll have to do this:

1 Like

Slight improvement!

However, now I am getting a “Connection Refused” message on a specific port.

PROXY-CADDY | {“level”:“error”,“ts”:1617058016.2914352,“logger”:“http.log.error”,“msg”:“dial tcp connect: connection refused”,“request”:{“remote_addr”:“117.x.x.x:50760”,“proto”:“HTTP/1.1”,“method”:“GET”,“host”:“”,“uri”:"/api/server/root-certificate-public-key",“headers”:{“X-Connectionguid”:[“b7e4086c-8b38-4b32-a4b6-b5d9560e13ef”],“X-Auth”:[""],“Accept”:[“application/json”]},“tls”:{“resumed”:false,“version”:771,“cipher_suite”:49196,“proto”:"",“proto_mutual”:true,“server_name”:“”}},“duration”:0.000960981,“status”:502,“err_id”:“h6iji5hn5”,“err_trace”:“reverseproxy.statusError (reverseproxy.go:783)”}

The firewall on the internal device is completely off (for testing) and the proxy server too. Not sure where exactly the connection is being refused. (Both machines are on private lan)

Appreciate any assistance (been fantastic so far)

Do you actually have a service listening on that port?

The specific ports are 8200 and 8206 (different from our 8001 discussion, but to keep it simple)

It seems, I can only get one TCP port connection at a time either 8200 is successful and 8206 is refused or vice versa…

Hi @francislavoie, tried doing some more troubleshooting and it seems my firewall ( is intercepting the packets and dropping them (presumably)

Anything i can put in the configuration file to help get around this issue? (Local machine) (Server machine running service) (Firewall) (Opnsense)

{“level”:“error”,“ts”:1617370780.5333998,“logger”:“http.log.error”,“msg”:“read tcp> read: connection reset by peer”,“request”:{“method”:“GET”,“uri”:"/api/server/root-certificate-public-key",“proto”:“HTTP/1.1”,“remote_addr”:“”,“host”:“”,“headers”:{“X-Auth”:[""],“Accept”:[“application/json”],“X-Connectionguid”:[“ec5f96-6a53-4430-ad5f-5816a72c6448”]},“tls”:{“resumed”:false,“version”:771,“ciphersuite”:49196,“proto”:"",“proto_mutual”:true,“server_name”:“”}},“duration”:0.000550915,“status”:502,“err_id”:“es2itsanc”,“err_trace”:“reverseproxy.(*Handler).ServeHTTP (reverseproxy.go:411)”}

I don’t know anything about that firewall, so there’s not much I can do to help.

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