Be part of JetBrains PHPverse 2026 on June 9 – a free online event bringing PHP devs worldwide together.

thebigk's avatar
Level 13

Caddy and Multi-Tenant (Subdomains) with HTTPS

I am trying to setup a multi-tenant application with Caddy server. The application works perfectly fine on my local setup with Laravel valet; allowing me to create subdomains with https. The following configuration works on production, allowing me to create subdomains. However, the system fails when I try to map a subdomain from client to a subdomain on my application.

I am unable to figure out if there's an error in my application OR the way I am configuring DNS.

I am replicating the entire setup on my test-domain: layoff.wtf

My Caddyfile Configuration:

{
        on_demand_tls {
                ask http://layoff.wtf/caddy/ask
                interval 2m
                burst 5
        }
}

https:// {
        tls {
                on_demand
        }

        root * /home/forge/layoff.wtf/public
        file_server
        php_fastcgi unix//run/php/php8.2-fpm.sock
}

This setup works perfectly to serve:

  1. My main domain: layoff.wtf with HTTPS
  2. Any subdomain: <subdomain>.layoff.wtf with HTTPS

Problem

My customer has created following subdomain on my SaaS: waitlist.layoff.wtf They want to serve it via their subdomain: support.waitlist.guru

Here's how the DNS has been configured for support.waitlist.guru:

CNAME | support | waitlist.layoff.wtf. | 600 seconds

That way, I thought when the user types support.waitlist.guru, they will be served my SaaS application from waitlist.layoff.wtf. However, they are being served the homepage on layoff.wtf and not the appropriate subdomain. You can actually type those names in browser and check.

DNS configuration for my SaaS domain: layoff.wtf is as follows:- A | @ | 13.233.62.52 | 600 seconds CNAME | * | layoff.wtf. | 600 seconds

How do I ensure that my customers can create their subdomains and map to their domain using a simple CNAME configuration; which I have seen on multiple SaaS offerings?

0 likes
1 reply
LaryAI's avatar
Level 58

The issue seems to be with the DNS configuration. To ensure that customers can create their subdomains and map them to their domain using a CNAME configuration, you need to make a few changes.

  1. Update the DNS configuration for the customer's domain, support.waitlist.guru, to point to your SaaS application's subdomain, waitlist.layoff.wtf. The CNAME record should be set as follows:
CNAME | support | waitlist.layoff.wtf. | 600 seconds
  1. In your Caddyfile configuration, you need to add a wildcard subdomain matcher to handle requests for any subdomain. Update the https block in your Caddyfile as follows:
https:// {
    tls {
        on_demand
    }

    root * /home/forge/layoff.wtf/public
    file_server
    php_fastcgi unix//run/php/php8.2-fpm.sock

    # Add this wildcard subdomain matcher
    @subdomain {
        host_regexp .+
    }

    # Route requests for any subdomain to the appropriate subdomain on your application
    reverse_proxy @subdomain http://waitlist.layoff.wtf
}

With these changes, requests to support.waitlist.guru should be correctly routed to waitlist.layoff.wtf, serving the appropriate subdomain of your SaaS application.

Make sure to restart Caddy server after making these changes for them to take effect.

Please or to participate in this conversation.