Proxying to multiple backends depending on the hostname

1. Caddy version (caddy version):

2.4.6

2. How I run Caddy:

Docker file (see below)

a. System environment:

Ubuntu 20.04

b. Command:

docker-compose up

{
    on_demand_tls {
        ask      http://railsplatform:3000/caddy_domain
        interval 2m
        burst    5
    }
}

https:// {
    tls {
        on_demand
    }
    reverse_proxy railsplatform:3000
}

Ok so I have the above configuration so far, I haven’t actually run it on the server just yet as I am still setting this up.

So I want my Caddyfile to be able to server requests for the following:

  1. Marketing website: example.com (or www.example.com)
  2. Customer domains which will create a DNS entry to point to: platform.example.com

So my Caddyfile will serve requests for the market website example.com, which should proxy requests to railsmarketing:3001.

My customers will make DNS entries to point to platform.example.com, these domains will need to use the on-demand lookup to verify that this domain should fetch a SSL certificate for. Requests for these domains should be proxied to a different backed like railsplatform:3000

My marketing website will also need a SSL certificate for example.com

What changes does my Caddyfile need, b/c currently it will proxy all requests to a single backend.

Thanks!

You can just add another site block for the specific sites you want to be handled specially:

example.com, www.example.com {
	reverse_proxy railsmarketing:3001
}

Or if you want to redirect www.example.com to example.com you can do this:

www.example.com {
	redir https://example.com{uri}
}

example.com {
	reverse_proxy railsmarketing:3001
}
2 Likes

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