How to Reverse Proxy on a Machine with Multiple IP Addresses?

3. The problem I’m having:

Hi, I have a Ubuntu 20.04 machine with a single network interface that has 3 IP addresses assigned to it. On this machine, I will like to run 3 instances of a program on this machine, each listening to a different port (8000, 8001, 8002).

Is it possible to configure Caddy to act as a reverse proxy for all traffic to these 3 IP addresses, so that they are routed to the correct instance of the program?

For example, if we have the IP addresses,,, we will like to configure Caddy such that

  • Program #1 listening to localhost:8000 <=> ┌────┐ <=>
  • Program #2 listening to localhost:8001 <=> │Caddy │ <=>
  • Program #3 listening to localhost:8002 <=> └────┘ <=>

Thank you!

Yep, you can use the bind subdirective to bind to a specific network interface:

Maybe something like this: {
	reverse_proxy localhost:8000
} {
	reverse_proxy localhost:8001

So this is a bit counter intuitive, but note that you still need to use bind even if you specify the IP in the site address, because Caddy will listen on regardless. Also, kinda awkward, but because it would be ambiguous, you need to specify a hostname (either an IP or domain) for the site address, otherwise Caddy will complain about duplicate site addresses (e.g. if you tried to use :8000 as the site address for both)

(Memo to self) Now that Caddy 2 is done, it might be worth investigating to see if this is still a necessary limitation, when the bind addresses are clearly different…

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