Nginx Subdomain Configuration Problems - Possibly a DNS Problem

May 9, 2019 594 views
Ubuntu Nginx

Hello. I’ve been working on setting up an nginx server setup the goal is to eventually script adding new subdomains but I’ve been having trouble with my initial test. I’ve read through a bunch of tutorials and they gloss over setting up the DNS records so I have a feeling that’s where the problem is. Any help would be much appreciated. I’ve probably missed something small but I can’t figure it out for the life of me.

Goal:

Have static site that is createdby.fi and multiple other static (and possibly later non-static) sites on subdomains like sub.createdby.fi.

Current State:

createdby.fi loads correctly, but sub.createdby.fi show index.html page from createdby.fi

Details on Setup:

Running: Ubuntu 18.04.2 LTS

DNS settings on Digital Ocean:

Type Hostname Value TTL
A sub.createdby.fi directs to ip 3600
A createdby.fi directs to ip 3600

Excluded domains CNAME (just www) and NS for brevity.

I briefly trying using a CNAME record but that didn’t fix the problem and one of the tutorials I read said A records were the way to go. If that’s wrong please correct me.

Hosts File:

127.0.1.1 createdby.fi
127.0.1.1 sub.createdby.fi
127.0.0.1 localhost

Nginx Config Files:

/etc/nginx/sites-available/createdby.fi (symbolic linked in sites-enabled)

server {
        listen 80 default_server;
        listen [::]:80 default_server;

        root /var/www/createdby.fi;

        index index.html;

        server_name createby.fi www.createdby.fi;

        location / {
                try_files $uri $uri/ =404;
        }
}

/etc/nginx/sites-available/sub.createdby.fi (symbolic linked in sites-enabled)

server {
        listen 80;
        listen [::]:80;

        root /var/www/sub.createdby.fi;

        index index.html;

        server_name sub.createby.fi www.sub.createdby.fi;

        location / {
                try_files $uri $uri/ =404;
        }
}

/var/www/createdby.fi and /var/www/sub.createdby.fi both have boilerplate html files with different different text.

server_names_hash_bucket_size 64; uncommented in /etc/nginx/nginx.conf otherwise unchanged

Nginx has been restarted and server was rebooted.

I’ve cleared the browser cache and even tried flushing dns and deleting temp files on my browser, so I don’t think that’s the problem.

2 Answers

Hi,
There is typo error in server name in both the blocks. In which case Request would be served by default server.
servername createby.fi
Correction=>
server
name createdby.fi

Great thanks! Much appreciated.

Have another answer? Share your knowledge.