nginx: setting up catch-all subdomains

November 8, 2015 2k 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 sub1.mydomain.com it will be the same as www.mydomain.com.

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   @   1.2.3.4  
CNAME record    *    domain.com. 
NS record ns1.digitalocean.com.
NS record ns2.digitalocean.com.
NS record ns3.digitalocean.com.

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.

1 Answer

Sorry to see that your question hasn't received an answer yet. Unfortunately, after this much time, it is unlikely that an answer for this specific question will be provided. Since the site is reachable on all subdomains most of the time and it is only unavailable during specific periods, it's more likely that the routing configuration is proper, but nginx/php/etc. are running out of resources causing the website to be temporarily unavailable. In that case, it might help to look at memory usage stats over time and during periods of unavailability, and checking logs for errors.

Have another answer? Share your knowledge.