Reverse Proxy with multiple subdomain

My Caddy version (caddy version):v2.0.0-rc.3

Hi, new user here. I’m trying to do multiple reverse proxy with subdomains. I’m able to get reverse proxy working with single IP but I can’t figure how to do it for multiple subdomain.

What I want is

subdomain1.example.com reverse_proxy to 10.0.0.1
subdomain2.example.com reverse_proxy to 10.0.0.2

This caddy file not working, caddy status has no errors, but I can’t access https://subdomain1.example.com

example.com {
reverse_proxy subdomain1.example.com 192.168.1.99:8888
reverse_proxy subdomain2.example.com 192.168.1.99:8889
}

If I use single reverse proxy, I can access via https://example.com
example.com {
  reverse_proxy 192.168.1.99:8888
}

1 Like

You’re looking for something like this:

subdomain1.example.com {
    reverse_proxy 192.168.1.99:8888
}

subdomain2.example.com {
    reverse_proxy 192.168.1.99:8889
}

With your Caddyfile, it was parsed as subdomain1.example.com and 192.168.1.99:8888 being separate proxy upstreams, which is why you got no error. You would get 50% of your requests working (using the default round robin load balancing policy), and the other half trying to load the subdomain but since that doesn’t serve anything, it would fail.

The only valid entries for the matcher argument are *, a path starting with / or a named matcher starting with @. See the matcher docs here:

Also, you can review the Caddyfile Concepts document which explains how the Caddyfile works:

5 Likes

Thanks for the reply. I tried that before, but I’m still unable to access.

    Caddy
    test.example.com {
    reverse_proxy 192.168.1.99:8888
    }

    testone.example.com {
    reverse_proxy 192.168.1.98:8889
    }

    caddy.service - Caddy
       Loaded: loaded (/etc/systemd/system/caddy.service; enabled; vendor preset: disabled)
       Active: active (running) since Fri 2020-05-01 00:34:42 EDT; 6s ago
         Docs: https://caddyserver.com/docs/
      Process: 4647 ExecReload=/usr/bin/caddy reload --config /etc/caddy/Caddyfile (code=exited, status=0/SUCCESS)
     Main PID: 4689 (caddy)
        Tasks: 6 (limit: 11486)
       Memory: 32.6M
       CGroup: /system.slice/caddy.service
               └─4689 /usr/bin/caddy run --environ --config /etc/caddy/Caddyfile

    May 01 00:34:43 localhost.localdomain caddy[4689]: 2020/05/01 00:34:43 [INFO][test.example.com] Done waiting
    May 01 00:34:43 localhost.localdomain caddy[4689]: 2020/05/01 00:34:43 [INFO] [test.example.com] acme: Obtaining bundled SAN certificate given a CSR
    May 01 00:34:43 localhost.localdomain caddy[4689]: 2020/05/01 00:34:43 [ERROR] acme: error: 429 :: POST :: https://acme-v02.api.letsencrypt.org/acme/new-order :: urn:ietf:params:acme:error:rateLimited :: Error creating new order :: too >
    May 01 00:34:44 localhost.localdomain caddy[4689]: 2020/05/01 00:34:44 [ERROR] acme: error: 429 :: POST :: https://acme-v02.api.letsencrypt.org/acme/new-order :: urn:ietf:params:acme:error:rateLimited :: Error creating new order :: too >
    May 01 00:34:45 localhost.localdomain caddy[4689]: 2020/05/01 00:34:45 [INFO] [testone.example.com] acme: Obtaining bundled SAN certificate given a CSR
    May 01 00:34:46 localhost.localdomain caddy[4689]: 2020/05/01 00:34:46 [ERROR] acme: error: 429 :: POST :: https://acme-v02.api.letsencrypt.org/acme/new-order :: urn:ietf:params:acme:error:rateLimited :: Error creating new order :: too >
    May 01 00:34:46 localhost.localdomain caddy[4689]: 2020/05/01 00:34:46 [INFO] [test.example.com] acme: Obtaining bundled SAN certificate given a CSR
    May 01 00:34:46 localhost.localdomain caddy[4689]: 2020/05/01 00:34:46 [ERROR] acme: error: 429 :: POST :: https://acme-v02.api.letsencrypt.org/acme/new-order :: urn:ietf:params:acme:error:rateLimited :: Error creating new order :: too >
    May 01 00:34:48 localhost.localdomain caddy[4689]: 2020/05/01 00:34:48 [ERROR] attempt 1: [testone.example.com] Obtain: [testone.example.com] acme: error: 429 :: POST :: https://acme-v02.api.letsencrypt.org/acme/new-order :: urn:i>
    May 01 00:34:48 localhost.localdomain caddy[4689]: 2020/05/01 00:34:48 [ERROR] attempt 1: [test.example.com] Obtain: [test.example.com] acme: error: 429 :: POST :: https://acme-v02.api.letsencrypt.org/acme/new-order :: urn:ietf:pa

Ok, I got it figured out, the A Record was not setup properly. It is working now, thanks.

1 Like

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