I am giving my services to my users via client.example.com
and there are pages like
client.mysite.com/blog
client.mysite.com/blog/content/
client.mysite.com/docs/
etc.
I want to allow users to allow their domains to point to this subdomain.
so they can choose between any of the 1 option below :
client.com -> client.example.com
sub.client.com -> client.example.com
client.com/sub/ -> client.example.com
and pages should work automatically like
client.com/blog -> client.example.com/blog
sub.client.com/blog -> client.example.com/blog
client.com/sub/blog -> client.example.com/blog
Also, I use Elastic beanstalk in amazon to deploy my react application with nginx (docker image ). Before I start I want to know if this is possible.I also don't want to give fixed ip address to my clients, just in case if I lose that IP. How are the big players like blogger.com , wordpress.com etc doing it? Thanks.
As far as I researched I know cname is possible to allow clients subdomains and we need IP address for named domain. nowhere it mentioned about the folder. And for SSL, I can use letsencrypt.
If some one explain in detail there will be a bounty in 2 days for this post ,I am ok with anything like cloudflare / route53 method , thanks again.
CodePudding user response:
Cloudflare for SaaS is designed for this use case. You would just go to Cloudflare Dashboard > You Domain (example.com) -> SSL -> Custom Hostnames. Add a fallback hostname to which you client will link to, e.g. ssl.example.com
.
Then client then would need to add his or her custom hostname in your app, then link and verify his custom domain by adding a CNAME
(pointing to ssl.example.com
) and TXT
record via his own DNS provider. The verification and issuing a new SSL would take a few minutes, completely handled by Cloudflare and from their own, your clients may access your service via custom hostname (e.g. client.com
, sub.client.com
, client.com/blog
etc.)
If you need to manipulate the HTTP response as it goes through the customer's hostname, it's also possible to route these request through a CLoudflare Worker script (linked to */*
— all hostnames/URLs).
Here is an example, of how to create a custom hostname programmatically:
import * as Cloudlfare from "cloudflare-client";
// Initialize custom hostnames client for Cloudlfare
const customHostnames = Cloudflare.customHostnames({
zoneId: process.env.CLOUDFLARE_ZONE_ID,
accessToken: process.env.CLOUDFLARE_API_TOKEN,
});
// Add the client's custom hostname record to Cloudflare
const record = await customHostnames.create(
hostname: "www.client.com",
ssl: {
method: "txt",
type: "dv",
settings: {
min_tls_version: "1.0",
},
}
);
// Fetch the status of the custom hostname
const status = await customHostnames.get(record.id);
// => { id: "xxx", status: "pending", ... }
References
- https://developers.cloudflare.com/cloudflare-for-saas/
- https://github.com/kriasoft/cloudflare-client
- https://github.com/kriasoft/cloudflare-starter-kit
CodePudding user response:
The simplest approach to this, which I’ve implemented at scale (10,000 clients), is to:
- Have your clients create a CNAME record to either a specific client.example.com or general clients.example.com. This applies to both root (set the ALIAS record instead) and subdomains—an IP address is not required, nor recommended as it does not scale.
- Create a database entry that registers/links that explicitly links their domain/subdomain to their account.
- Have logic in the backend controller will that associates the hostname in the request to a specific client (security measure) to serve relevant content.
The above fulfills the first two use cases—it allows the client to link a root domain or subdomain to your service.
To achieve the third use case, you could allow the client to specify an arbitrary root path for your service to run within. If the client chooses this, you also need to handle redirects to other services that they have on their domain. This is a lot of responsibility for your app, however.
You could just leverage their registrar, most registrars have the ability to do path redirects—this is the simplest approach that requires the least amount of responsibility/maintenance on your end.
I also recommend having an option for redirecting all entry points (ie: root domain, subdomain, root domain path, subdomain path) to a primary entry point (ie: root domain path), for SEO purposes.
Note: You may also use a service, such as wwwizer, that redirects to the www specified if the ALIAS option on the root domain of your client isn't available.