Dynamic Domain Redirection
d1100101_1101110_1101001_1110011
HOBBYOP

a year ago

I am experiencing issues dynamically redirecting multiple domains to a primary domain (domain1.com) using Caddy. I am building a website builder, and I need my clients to be able to dynamically set up their domains.

My current setup involves:

  1. Primary Domain Setup: domain1.com is set up and working correctly, serving from the specified directory via Caddy.

  2. Dynamic Domain Management: I have multiple additional domains (domain2.com, domain3.com, etc.) that need to be redirected to domain1.com. These domains are stored in a database and fetched via an API.

Caddyfile Configuration:

{

    admin off

    persist_config off

    auto_https off

    log {

        format json

        output stdout

    }

    servers {

        trusted_proxies static private_ranges

    }

}

:{$PORT} {

    log {

        output stdout

        format json

    }

    route /health {

        respond "ok" 200

    }

    root * /app/dist/apps/editor/browser

    encode gzip

    file_server

    try_files {path} /index.html

}

Issue:

I tried setting up a CNAME record for custom domains to point to domain1.com, but I receive the following error:

Not Found
The train has not arrived at the station.

Please check your network settings to confirm that your domain has provisioned.

If you are a visitor, please let the owner know you're stuck at the station.

Request ID: UgIBmrEcRMy89Y1JiMPHjA_2823689937

Question: How can I dynamically add domain redirections without redeploying my application?

1 Replies

brody
EMPLOYEE

a year ago

Railway does host based routing, meaning if the domain isn't in your service settings Railway doesn't know what to route the given domain to so it returns 404, for this you would need to use a wildcard domain.

Eg. *.domain.com

Then you could do hostname matching for any subdomain on domain.com, 1.domain.com, 2.domain.com


Loading...