'Handling custom users domains in nginx (SaaS)

I have a small SaaS website and I need to handle custom users domains.

custom.clientdomain.com -> (CNAME) domains.saaswebsite.com -> (USER SEE THIS PAGE) saaswebsite.com/shop/id/

I want to take id from TXT record of clientdomain.com. My website uses nginx and cloudflare. I already have SSL for SaaS. My DNS records: dns records

My SSL for SaaS configuration: enter image description here

My nginx configuration:

server {
  server_name www.saaswebsite.com saaswebsite.com domains.saaswebsite.com;
    location / {
    root /var/www/vishop/frontend/frontend/dist/;  #-> index.html location
    index index.html;
    include  /etc/nginx/mime.types;
    try_files $uri $uri/ /index.html;
  }
}


Sources

This article follows the attribution requirements of Stack Overflow and is licensed under CC BY-SA 3.0.

Source: Stack Overflow

Solution Source