Nginx not able to serve subdomain on same server as domain

On my nginx server (ubuntu 18.04), I want to host and, where is one index.html file and is a proxy to my node js api, which is running on port 3001.

I have 2 files in /etc/nginx/sites-available folder called and and here are the contents from those files.

// server {         listen 80;         listen [::]:80;          root /var/www/;         index index.html          server_name;          location / {                 try_files $  uri $  uri/ =404;         } }  // upstream domain_apis {         server;         keepalive 64; }  server {     listen 80;     server_name;   location / {         proxy_set_header X-Forwarded-For $  proxy_add_x_forwarded_for;         proxy_set_header X-Real-IP $  remote_addr;         proxy_set_header Host $  http_host;          proxy_http_version 1.1;         proxy_set_header Upgrade $  http_upgrade;         proxy_set_header Connection "upgrade";          proxy_pass http://domain_apis/;         proxy_redirect off;         proxy_read_timeout 240s;     } } 

when I hit, things are working fine. But when I hit, it serves the page from root folder. I have replaced reverse proxy with simple server with another subdomain, but it always serves the root domain.

Any ideas on how to debug this and how to check if requests are hitting the correct block?