nginx: prevent open first available site on different port

Here is an example configuration.

    server {
    listen 8080;
    server_name a.x.com;
    ...
}

server {
    listen 8081 ssl;
    server_name a.x.com;
    ...
}       

    
server {
    listen 80;
    server_name  b.x.com;
}   

server {
    listen 443 ssl;
    server_name b.x.com;
    ...
}               

#supposedly the default folder  
server {
    #https://stackoverflow.com/a/9454825/4546246
    listen       80 default_server;
    #listen       443 default_server;
    server_name  ~^(.+)$;
    location / {
        root   html;
        index  index.html index.htm;
    }
    error_page   500 502 503 504  /50x.html;
    location = /50x.html {
        root   html;
    }
}

open htpps://a.x.com:8081 -> (NO PROBLEM) open https://b.x.com -> (NO PROBLEM)

but

open https:/a.x.com (without port) -> it's opening the files of b.x.com.

supposedly what was expected was to open the html folder

where am I doing wrong?


You haven't defined a server block for a.x.com for the port 443. The only server block you defined for port 443 is b.x.com, so that's what you are getting.