nginx: setting up catch-all subdomains

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.


Submit an 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.

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.