允许用户将他们的域名指向我的服务

Gra*_*ams 5 dns nginx amazon-web-services cloudflare amazon-elastic-beanstalk

client.example.com我通过以下方式向我的用户提供服务:

client.mysite.com/blog
client.mysite.com/blog/content/ 
client.mysite.com/docs/ 
Run Code Online (Sandbox Code Playgroud)

ETC。

我想允许用户允许他们的域指向这个子域。

因此他们可以在以下 1 个选项中进行选择:

  client.com -> client.example.com
  sub.client.com -> client.example.com
  client.com/sub/ -> client.example.com
Run Code Online (Sandbox Code Playgroud)

并且页面应该自动工作,就像

 client.com/blog -> client.example.com/blog
 sub.client.com/blog -> client.example.com/blog
 client.com/sub/blog -> client.example.com/blog
Run Code Online (Sandbox Code Playgroud)

另外,我在 Amazon 中使用 Elastic Beanstalk 通过 nginx(Docker 映像)部署我的 React 应用程序。在开始之前,我想知道这是否可行。我也不想向我的客户提供固定的 IP 地址,以防万一我丢失该 IP。blogger.com、wordpress.com 等大公司是如何做到的?

据我研究,我知道 cname 可以允许客户端子域,并且我们需要命名域的 IP 地址。它没有提到该文件夹​​。对于 SSL,我可以使用 LetsEncrypt。

我对 CloudFlare / Route53 等方法都满意。

Kon*_*kus 7

Cloudflare for SaaS专为此用例而设计。您只需转到 Cloudflare Dashboard > You Domain (example.com) -> SSL -> Custom Hostnames。添加您的客户端将链接到的后备主机名,例如ssl.example.com

\n

然后,客户需要在您的应用程序中添加他或她的自定义主机名,然后通过添加CNAME(指向ssl.example.com)并TXT通过他自己的 DNS 提供商记录来链接和验证他的自定义域。验证和颁发新的 SSL 需要几分钟时间,完全由 Cloudflare 处理,从那时起,您的客户可以通过自定义主机名(例如 、 等)访问您client.com的服务sub.client.comclient.com/blog

\n

如果您需要在 HTTP 响应通过客户主机名时对其进行操作,也可以通过 CLoudflare Worker 脚本(链接到*/*\xe2\x80\x94 所有主机名/URL)路由这些请求。

\n

以下是如何以编程方式创建自定义主机名的示例:

\n
import * as Cloudlfare from "cloudflare-client";\n\n// Initialize custom hostnames client for Cloudlfare\nconst customHostnames = Cloudflare.customHostnames({\n  zoneId: process.env.CLOUDFLARE_ZONE_ID,\n  accessToken: process.env.CLOUDFLARE_API_TOKEN,\n});\n\n// Add the client\'s custom hostname record to Cloudflare\nconst record = await customHostnames.create(\n  hostname: "www.client.com",\n  ssl: {\n    method: "txt",\n    type: "dv",\n    settings: {\n      min_tls_version: "1.0",\n    },\n  }\n);\n\n// Fetch the status of the custom hostname\nconst status = await customHostnames.get(record.id);\n// => { id: "xxx", status: "pending", ... } including TXT records\n
Run Code Online (Sandbox Code Playgroud)\n

价钱

\n

CF for SaaS 对于 100 个主机名是免费的,之后每个主机名/月 0.10 美元(来源)。

\n

基于路径的 URL 转发

\n

如果您需要将HTTP流量转发到不同的端点,例如www.client.com/*(客户域)到web.example.com(SaaS端点);www.client.com/blog/*blog.example.com

\n

您可以通过创建一个带有处理*/*请求的路由(所有客户主机名和所有 URL 路径)的 Cloudfalre Worker 脚本来实现这一点,该脚本类似于以下内容:

\n
export default {\n  fetch(req, env, ctx) {\n    const url = new URL(req.url);\n    const { pathname, search } = url;\n\n    if (url.pathname === "/blog" || url.pathname.startsWith("/blog/")) {\n      return fetch(`https://blog.example.com${pathname}${search}`, req);\n    }\n\n    return fetch(`https://web.example.com${pathname}${search}`;\n  }\n}\n
Run Code Online (Sandbox Code Playgroud)\n

参考

\n\n