如何给saas软件提供cname转发支持

发布于 2024-07-24 04:51:40 字数 270 浏览 4 评论 0原文

我有一个网络应用程序,用户可以在其中创建帐户并使用该服务。 现在我想给他们一个自定义域工具,其中 app.customer1web.com 指向 myservice.com,用户 ID 为 customer1 一旦他设置了自定义域,对于全世界来说,我的服务看起来就像在他的计算机上运行。 许多服务,如 blogger、wp.com、tumblr 都提供 此功能。

我怎么做? 我正在使用 java 来编写我的网络应用程序。 当请求到来时,如何将域名映射到用户ID?

I have a webapp where users can create their account and use the service. Now I want to give them a custom domain facility where
app.customer1web.com points_to myservice.com with userid customer1
once he sets up the custom domain, for the world it looks like my service is running on his machine.
Many services like blogger, wp.com, tumblr give
this feature.

how do i do that?
I am using java to write my web app.
How do i map domain name to userid when request comes in?

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(4

○闲身 2024-07-31 04:51:40

当请求到来时,如何将域名映射到用户ID?

显然,您必须将该信息存储在某个地方,很可能存储在数据库中。

  1. 添加包含列的数据库表domains

    • 客户ID
    • 姓名
    • 活动(1 或 NULL)
    • 挑战

    为(name,active)添加唯一键,以确保域名仅映射一次。

  2. 当客户尝试添加域时,添加一行 active=NULL 并将质询设置为随机字符串。

    向客户显示随机字符串,并要求他们在网站上放置包含该字符串的网页,或使用该字符串创建虚拟 DNS 记录以验证域所有权(Google Apps 就是这样做的)。

    您可以通过向管理联系人发送电子邮件或以其他方式验证所有权。

  3. 当客户说他做了您在第 2 步中指示他们做的事情时,请进行验证并设置 active=1、challenge=NULL。

    如果该域之前对其他客户有效,请删除这些记录或设置 active=0。

  4. 要求客户为其域添加 CNAME 记录并将其转发到您的域,例如 hosted.myservice.com(Google 使用 ghs.google.com Google Apps)。

  5. 当请求到来时,执行

    从域名中选择 customerId,其中 name=:requestDomain AND active=1 
      

更好的方法可能是自动为您的客户提供格式为 .myservice.com, 除了自定义域之外。 这给您带来两个好处:

  • 不想使用自己的域的客户仍然可以自定义他们的登录页面,例如使用公司徽标。

  • 对于自定义域,您可以要求客户将其转发到 .myservice.com,而不是通用的 hosted.myservice.com。< /p>

    这使您能够在多个服务器之间水平划分客户,而无需要求客户对其进行任何更改。 例如,您可以为客户提供一个选项,让他们选择是否希望将其帐户托管在欧盟或美国。 当他们更改时,只需传输数据并更新 .myservice.com。 他们的自定义域将自动工作。

为此,您必须为 *.myservice.com 设置通配符 DNS 记录(除非您还需要后一个功能,在这种情况下,您必须管理单独的记录)。

How do i map domain name to userid when request comes in?

Obviously, you'll have to store that information somewhere, most likely in a database.

  1. Add a database table domains with columns:

    • customerId
    • name
    • active (1 or NULL)
    • challenge

    Add unique key for (name, active) to ensure a domain name is mapped only once.

  2. When a customer attempts to add a domain, add a row with active=NULL and challenge set to a random string.

    Show the random string to the customer and ask them to put up a web page with it on the site or create a dummy DNS record with it to verify domain ownership (this is how Google Apps do it).

    You could verify ownership by sending an email to the administrative contact or in some other way.

  3. When the customer says he did what you instructed them to do in step #2, verify it and set active=1, challenge=NULL.

    If the domain was previously active for some other customer, delete those records or set active=0.

  4. Ask the customer to add a CNAME record for their domain and forward it to your domain, e.g. hosted.myservice.com (Google uses ghs.google.com for Google Apps).

  5. When a request comes in, do

    SELECT customerId FROM domains WHERE name=:requestDomain AND active=1
    

A better way may be to automatically offer your customers a domain in the format of <customername>.myservice.com, in addition to custom domains. This gives you two benefits:

  • Customers who don't wan't to use their own domain can still customize their login page, e.g. with a company logo.

  • For custom domains, you can ask your customer to forward them to <customername>.myservice.com instead of to a generic hosted.myservice.com.

    This enables you to horizontally partition customers among multiple servers without having to ask customers to change anything on their end. For example, you could give customers an option to choose whether they want their account hosted in EU or US. When they change it, just transfer their data and update <customername>.myservice.com. Their custom domain will work automatically.

To do this, you'd have to set up a wildcard DNS record for *.myservice.com (unless you also need the latter feature, in which case you'll have to manage individual records).

囍孤女 2024-07-31 04:51:40

您可以使用的一种解决方案是为您的应用程序设置通配符 DNS 记录,并让该应用程序它本身会检查 RequestURI 以查看用户进入的主机名。

我知道这是一个非常模糊的答案,但听起来设置通配符记录并使用单个函数检查主机名是最好的选择。 这样,您就不必在每次客户注册时都设置 DNS 记录,并且您有更多的时间自己做其他事情......例如向您的应用程序添加新功能!

One solution you could use is setting up a WildCard DNS Record for your application, and have the application itself check the RequestURI to see what host name the users are coming in on.

I know this is a very vague answer, but it sounds like having the WildCard record set up, with a single function checking the hostname is your best bet. This way, you do not have to set up a DNS record every time a customer signs up, and you have more time to yourself to do other things... like adding new features to your application!

装迷糊 2024-07-31 04:51:40

我不太确定我是否真的理解您想要做什么,但我尝试为您提供一个可能的解决方案(至少对于您问题的 Java 部分)。

一种可能性是以每个请求都由一个 Servlet (web.xml) 处理的方式设置应用程序服务器。 此 servlet 可以找到有关请求 url (HttpServletRequest.getRequestURI)并提取用户名。 然后您就了解了用户,并可以使用这些信息来做您想做的任何事情。

请注意,您想做的事情涉及很多 DNS 内容! (至少据我了解。)

I am not quite sure if I really understand what you would like to do but I try to give you a possible solution (at least for the Java part of your problem).

One possibility would be to set up your application server in a way that every request is handled by one single Servlet (web.xml). This servlet can find out about the request url (HttpServletRequest.getRequestURI) and extract the username. Then you know about the user and can use this information for whatever you would like to do.

Be aware that there is a lot of DNS-stuff involved in what you would like to do! (At least as fare as I understand it.)

椵侞 2024-07-31 04:51:40

@jaka 的答案解释得很好。 要添加更多内容,如果您使用 ngnix 作为 LB,它可以使用以下配置转发原始主机名。

proxy_set_header Host $host;

如果您使用的是express(nodejs),您可以从请求标头中读取主机名(cname)。 您可以使用 cname 和用户 cookie 进行授权检查。

对于证书,您可以使用 *.example.com(通配符)。

@jaka's answer is well explained. To add more on to it, If you're using ngnix as a LB, it can forward the original hostname using the below configuration.

proxy_set_header Host $host;

If you're using express (nodejs), you can read hostname(cname) from the request headers. You can do your authorization checks with cname and user cookies.

For the certificate you can go with *.example.com (wildcard).

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文