Report this

What is the reason for this report?

Accept CNAME DNS requests thru nginx with multiple domains

Posted on August 25, 2014

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 http://9374e93535f77f33.pages.bootlander.com) 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 http://anysub.theirowndomain.com => http://9374e93535f77f33.pages.bootlander.com.

When i did a test for this, the default first nginx virtual host loaded up and not the http://9374e93535f77f33.pages.bootlander.com 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;

     }


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!

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.

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 *.pages.bootlander.com in their browser.

The developer cloud

Scale up as you grow — whether you're running one virtual machine or ten thousand.

Get started for free

Sign up and get $200 in credit for your first 60 days with DigitalOcean.*

*This promotional offer applies to new accounts only.