Proxying any domain based on bind IP


(AlekseyP) #1

Hi there!

I’m trying to setup a system, where I bind multiple public IPs (both v4 and v6) and using proxying them to different backends. I would like it to work with any domain, but can’t make it work.

i’m either getting duplicate key error when I try to use just port as label, etc - or “site … is not served on this interface” when I use IP as label.

[ip:v6:ip::number1:as:label] {
    bind ip:v6:ip::number1:as:label
    proxy / http://backend3:80 http://backend4:80 {
        transparent
    }
        tls {
            max_certs 10
        }
}

:80 :443 [ip:v6:ip::number2:as:label] {
    bind ip:v6:ip::number2:as:label
    proxy / http://backend5:80 http://backend6:80 {
        transparent
    }
        tls {
            max_certs 10
        }
}

ipv4:address:here:number1:443 {
    bind ipv4:address:here:number1

    proxy / http://backend1:80 http://backend2:80 {
        transparent
    }
        tls {
            max_certs 10
        }
}

* {
    bind ipv4:address:here:number2

    proxy / http://backend7:80 http://backend8:80 {
        transparent
    }
        tls {
            max_certs 10
        }
}

I’ve also tried with * - it works for one block, but when i try to use it for multiple - i’m getting:

error inspecting server blocks: duplicate site key: *

Right now my only option is to run multiple caddy daemons.


(Matthew Fay) #2

Hi @alekseyp, welcome to the Caddy community!

Yeah, Caddy doesn’t use the bind interface to add uniqueness to site labels. To do this in a single Caddyfile you’d need unique labels. You will not be able to serve two different site definitions from one site label (including *) by differentiating with bind.

Multiple Caddy instances is probably the neatest way to do it, really. It’d be logical to use one Caddy instance per interface.


(AlekseyP) #3

Thank you very much! That’s what I ended up doing. Will probably just move to docker setup.
Still would be cool, to just have one daemon :stuck_out_tongue: