Accept CNAME DNS requests thru nginx with multiple domains

Ok, The title sounds very problematic… My current stack is a single server, with nginx as front server and a nodejs server in the back along side some apache virtual hosts.

The nginx has multiple virtual hosts per domain. everything works just fine.

This is where it gets complicated. One of my hosted nodejs apps accepts subdomains as var (i.e this is proxy_forward to http://nodejs:port/t/$subdomain which works great.

What i want todo is offer the option to let my customers put a DNS CNAME record on their DNS server that will take =>

When i did a test for this, the default first nginx virtual host loaded up and not the content.

What can i do?

This is the subdomains server block on nginx:

listen 80; 

    server_name   ~^([a-z0-9]+)\.pages\.bootlander\.com$;
    set $sub $1;
    location / {

    proxy_set_header X-Real-IP  $remote_addr;
    proxy_set_header X-Forwarded-For $remote_addr;
    proxy_set_header Host $http_host;
    proxy_pass http://nodejs:port/t/$sub;


Submit an answer

This textbox defaults to using Markdown to format your answer.

You can type !ref in this text area to quickly search our full set of tutorials, documentation & marketplace offerings and insert the link!

Sign In or Sign Up to Answer

These answers are provided by our Community. If you find them useful, show some love by clicking the heart. If you run into issues leave a comment, or add your own answer to help others.

Want to learn more? Join the DigitalOcean Community!

Join our DigitalOcean community of over a million developers for free! Get help and share knowledge in Q&A, subscribe to topics of interest, and get courses and tools that will help you grow as a developer and scale your project or business.

You will need to set server_name to whatever record your customers use to reach the site, otherwise nginx will load the default site. Your config at the moment will only work if a user directly enters * in their browser.