How to handle "custom domain" in a multitenant app in laravel forge
Hi, I have a multitenant laravel site that allows our customers to bring in their own custom domain for white labeling. So in our laravel app there is a middleware that detects the tenant based on the domain that is requesting the site content. I instruct my customers to add a "A" record that points to my server's IP address so that my server can load the content based on the domain being accessed. Now the issue is with this structure when a customers custom domain is accessed instead of loading the laravel site that we have it just redirects to the main domain of our laravel site for example if our site is at domain.com and the custom domain is custom.com and we setup a "A" record that points to our server's IP address then upon visiting custom.com it just redirects to domain.com instead of loading the contents of domain.com, your help is appreciated Thank you :)
@JussiMannisto Nope all my customer domains point to a single application and my application level logic takes care of loading the specific content of the specific tenant
@iftekhs That won't work. You have to configure a virtual host for each domain, but they can all point to the same Laravel instance.
If the web server receives a request addressed to customer.domain.com and that isn't found in the virtual host list, how should the server know what to do with it? And how would it know which SSL certificate & private key to use?
The answer is: it can't. It'll forward the request to the first host configured on that port. This is what's happening to you.
@JussiMannisto You are correct but after adding the alias it was able to understand which site content to load and about SSL I require all of my customers to use cloudflare with "flexible" SSL mode, this is until I build a system to automatically install SSL on my server for each custom domain. Thank you so much for your response :)
@JussiMannisto yes because I require all of my clients to use cloudflare with "flexible" SSL mode because did not built a system to programatically install SSL for all custom domains yet
@akazad91 I did this about two weeks ago. It's pretty involved and assumes you are using Cloudflare or a similar DNS service if you want clients to be able to bring their domain.
On the forge side, you need nginx to accept any domain e.g.
You set up the client subdomain on your system e.g. client-a.my-saas.com
The client adds their subdomain e.g. crm.the-client.com and you then add that to YOUR Cloudflare account as a custom hostname (I've automated this process via the Cloudflare API)
The client then adds a CNAME to their DNS, which would point to client-a.my-saas.com
When set up, the client therefore has HTTPs to your system but via their own custom domain.