Custom domain feature for saas product customers

拥有回忆 提交于 2020-08-22 05:41:22

问题


I have build a saas product with angular 4 integrated with golang rest api and uploaded the build on aws ec2 instance. My project is a multi-tenant based app which loads customers dashboard on merchant-name.mystore.com subdomain but some of the customers asking for custom domain feature like they should be able to load the app on mydomain.com .

I have done the the subdomain part with following code in apache2.conf file so all subdomain loads from apps folder where the angular app files located

<VirtualHost *:80>
    ServerAlias *.mystore.com
   DocumentRoot /var/www/html/apps
    <Directory "/var/www/html/apps">
        AllowOverride All
        Require all Granted
    </Directory>
</VirtualHost>

For custom domain feature I have a section in admin to save custom domain but not sure how should I implement it.

possible method I thought about are

  1. Create virtual host file and update it on each merchant signup with his custom domain
  2. Do it somehow with htaccess file and mod_rewrite

Shopify do it but not sure how they load merchant specific store. Another point kept me busy thinking about is what values should I ask to update

  1. IP address on domain registrar
  2. Name servers ( not sure what it will be for my on aws )
  3. Ask to create CNAME or A record as some of the article suggest

回答1:


I have a similar setup on a number of SaaS platforms I develop and manage. This type of setup is certainly desirable, as your clients suggest. You should plan to serve each customer site on its own domain, probably also with *SSL, from the begining. In my opinion, this is best practice for a well architected Saas service today.

In reading your question, I think you are over engineering it a little.

For a custom domain Saas app on the same server, you simply open port 80 to all traffic, regardless of domain name. Point all customer domains to app.mystore.com, which is a CNAME to your app endpoint.

The app then reads the HTTP request header, and in that way determines the host name that was requested.

Finally the app looks up the host name in its client database, and locates the client record for the give customer domain.

For example, in Nxinx all you need is:

server {
    listen       80 default_server;
    server_name  _;
    root         /var/www/myservice/htdocs;
}

This server configuration provides a catch all for any domain that points to this endpoint.

That is all the web server should need to allow it to answer to any customer domain. The app must do the rest.

* When you serve a custom domain on an app on this domain, you should plan to serve the SSL endpoint for the domain, eg https://www.mycustomdomain.com. Consider this in your architecture design. Consider also the DNS issues also if your app fails over to a new IP.



来源:https://stackoverflow.com/questions/48226382/custom-domain-feature-for-saas-product-customers

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!