I’m testing a DNS multitenant config but I can’t configure Nginx as I want.
I have a domain mydomain.com with A DNS rule for redirecting all subdomains (*) to my server IP.
If I enter the URL of my erpnext subdomain, https://erpnext.mydomain.com, I get Erpnext, so till here all is fine
if you have given *.yourdomain.com in your DNS server, then it wildcard match for anything before your domain name.
You should update DNS record with @.yourdomain.com 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.
I plan to deploy several sites, so I think *.mydomain.com 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 :
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 :
another one listens 80 port on the same server_name = site1.mydomain.com for http to https redirecting.
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!