DEV Community

Cover image for Mix Netlify DNS and other subdomains
Vittorio Zamboni
Vittorio Zamboni

Posted on

Mix Netlify DNS and other subdomains

Cover image: Wicklow Mountains, Co. Wicklow, Ireland

The last time I created a blog was few years ago, and WordPress was still the most popular choice to reduce the effort and have a decent piece of functionality.
Recently, after learning some React and following the community choices, I really liked Gatsby.

Creating a static blog can reduce the complexity of the architecture: no more database, no more host running PHP, simpler configurations for Nginx.

A plus is also the possibility to use services like Netlify to host your blog's build. The main points are: it's free, it builds automatically after a new commit is pushed to your preferred brach and it manages DNS for you.

Last part is a little bit tricky if you already own a domain and you already have other applications running on different subdomains.

Deploy to Netlify

With few easy steps, it is possibly to deploy your repository directly to Netlify. A blog post in their website explains really well how to do this.
In summary, you will:

  • add your respository from your Netlify dashboard by clicking on "New site from GIT" (and choose one of Github, GitLab or Bitbucket);
  • grant Netlify's app the required permissions;
  • proceed with default settings and deploy.

This will generate one subdomain for you, like if you navigate to this URL your blog will be there!

DNS Provider settings

Following Netlify's guide, I set the domain name ( as Primary Domain and WWW subdomain as domain alias.
This worked perfectly for both of them, but unfortunately I lost access to my other applications reachable by different subdomains (

I then moved my main configuration to my DNS provider built in service (I am using Gandi as DNS provider and Linode as VM provider).

I wanted to have my domain (without subdomain), blog and www subdomains to point to Netlify, but all other subdomains to point to my Linode instance (with1.2.3.4 as IP address).

This is the result:

@ 10800 IN A
@ 10800 IN MX 10
@ 10800 IN MX 50
@ 10800 IN TXT "v=spf1 ?all"
blog 1800 IN CNAME
second-app 1800 IN CNAME
www 10800 IN CNAME
Enter fullscreen mode Exit fullscreen mode
  • The first entry says that my primary domain has to be routed to my Linode instance (the other starting with @ are just the default example of a Gandi configuration).
  • blog and second-app subdomains are routed to;
  • www subdomain is routed to my netlify subdomain.

Note: you will need DNS entries to propagate before testing, this might take few hours

Configure Nginx for redirect

The first line of the configuration alone will not allow us to have our main domain pointing to Netlify's instance: we need to tell it to route to our www subdomain destination.

This is the simple Nginx configuration use to redirect:

server {
    rewrite ^/(.*)$$1 permanent;
Enter fullscreen mode Exit fullscreen mode

If you also want to have your blog subdomain to point to Netlify, add:

server {
    return 301$request_uri;
Enter fullscreen mode Exit fullscreen mode

Additional rules will handle your second-app subdomain.
A standard configuration might be like this:

upstream second-app {
    server;  # stram to a different port

server {
    listen 80;
    location / {
        proxy_set_header Host $host;
        proxy_set_header X-Real-IP $remote_addr;
        proxy_set_header X-Forwarded-For $proxy_add_x_forwarded_for;
Enter fullscreen mode Exit fullscreen mode

Netlify DNS configuration

The last step is to configure your domain in Netlify.
By default, guides tells you to set the primary domain as primary domain (obviously!).

When you do this, a www subdomain configuration is also added:


In this way however you will see some errors in the console due to our configuration, like this:


To avoid this, we need to swap the configuration in Netlify, by setting our www domain as primary domain:


Et voila'! All our DNS are setup to work correctly by mixing our host and Netlify.

Top comments (1)

mrxinu profile image
Steve Klassen (They/Them)

Great blog post! Lots of good information in here especially for those not familiar with DNS records.