Nginx behavior for unknown subdomain


I’m testing a DNS multitenant config but I can’t configure Nginx as I want.
I have a domain with A DNS rule for redirecting all subdomains (*) to my server IP.
If I enter the URL of my erpnext subdomain,, I get Erpnext, so till here all is fine :slight_smile:

But even if I enter an unexistant subdomain, nginx serves the same Erpnext site : serves

I would prefer having an error : unavailable site if nginx can’t link the subdomain with an existing Erpnext site.

Thanks for the help and don’t hesitate to ask if I’m not clear.

PS : I have the last bench.

strange. this shouldn’t happen and it should show not found.

If you haven’t modified the nginx config, try running bench setup nginx again and reloading nginx.

Just for confirmation: what’s the bench branch that you are using? master? or have you checked out a tag?

if you have given * in your DNS server, then it wildcard match for anything before your domain name.
You should update DNS record with if you don’t want it to occur.

The web server is doing what it told to do, serve!
and ERPNext nor Nginx has nothing to do with DNS setup directly.


I can confirm that with the installation-script provided on github and the commands for multi-setup you can easily use multi-dns.

The only thing you need to understand is that behind firewalls the NAT is not always working as expected. If you are not into network basics and NAT, you should stick with internal config and maybe VPN.

BTW: did you use:

bench seturlroot …
sudo service nginx restart


I’m on branch master, I updated about one week ago.
I tried to setup nginx and restart but got same result.

I plan to deploy several sites, so I think * is a good DNS rule to send all subdomains to my server.
If I understand, nginx tries to match the subdomain with an erpnext site :


Hi Sir,

I’d recommend doing it like:

Much easier :wink:

site1 is served because Nginx will always serve default site as per its configuration and it will happen in all case. Unless you change Nginx config and setup another site with default welcome page or information page which will not be associated with ERPNext.

You are right, I 've just understood. If no server_name matching in nginx.conf then nginx will serve the first server block of the conf file, that 's why my first site is always served with unknown subdomain.
It seems it is also possible to specify the default server in any server block :

But anyway, to do what I want, I just need to change my DNS rules by deleting wildcard rule and add each erpnext subdomain/site individually.

Thank you all for your precious help :slight_smile:

Or create a default http server block that shows site not found :slight_smile:

I think ERPNext production install removed that, which we shouldn’t.

Ideally ERPNext should not select one of its blocks as default since there is always going to be a one to one map.

Can you check if there’s a default keyword in the nginx Conf generated by ERPNext? I had removed it afaik.


There is no default keyword in the nginx conf generated by ERPNext.
I have only 2 server blocks for now :

I could indeed create a default server block that shows “site not found” but I don’t want to manually modify the nginx config generated by ERPNext, because I need to do it again each time I will run bench setup nginx


write a script to do that modification, its a custom job after all.

WHM/cPanel comes with functionality where, whenever Apache/PHP is upgraded, it regenerates apache config similar to the bench tool does do with bench setup nginx, but in cPanel there is an extra option to include file or shell code which executes pre and post execution of main rebuild function. It will be awesome if we can have that with bench too!