nginx: setting up catch-all subdomains

November 8, 2015 736 views
Nginx DNS Linux Basics Ubuntu

I have a website hosted with nginx on a D.O. droplet.
What I want(and hoped I achieved) is to have the same content served on all subdomains: www, sub1, sub2 etc. So if user goes to it will be the same as

DNS and nginx config were not modified in the last month and everything appears to be fine: ping to all subdomain go to correct ip, also in browser content is served for any subdomain.

The problem is that there are periods when server is not reachable(biggest one was 10 minutes) and I can't seem to find what the problem is. Could it be something with DNS or nginx config of my subdomains ?

My DNS is setup like this(ip/domain are just as an example, not my real values):

A record   @  
CNAME record    * 
NS record
NS record
NS record

Also I have used default configuration file for nginx:

server {
    listen 80 default_server;
    listen [::]:80 default_server ipv6only=on;

    root /usr/share/nginx/html;
    index index.php index.html index.htm;

    server_name localhost;

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

    error_page 404 /404.html;
    error_page 500 502 503 504 /50x.html;
    location = /50x.html {
        root /usr/share/nginx/html;

Any help is appreciated.

Be the first one to answer this question.