Search code examples
nginxdnspm2

NGINX defaulting to welcome page on Second domain name pointing to node server


I have a Single Page Application running on a node server serving angular at www.xxx.com. This is currently working.

I am trying to server a second Node application named www.yyy.com however when I set up the NGINX server blocks it is defaulting to the NGINX welcome page.

www.xxx.com NGINX server block (Which is working fine):

server {
listen 80;
listen [::]:80;
server_name xxx.com.au www.xxx.com.au;
return 301 https://xxx.com.au$request_uri;
}


server {
listen 443;
server_name xxx.com.au www.xxx.com.au;

location / {
    proxy_set_header X-Real-IP $remote_addr;
    proxy_set_header X-Forwarded-For $proxy_add_x_forwarded_for;
    proxy_set_header Host $http_host;
    proxy_set_header X-NginX-Proxy true;
    proxy_pass http://127.0.0.1:3000/;
    proxy_redirect off;
    proxy_http_version 1.1;
    proxy_set_header Upgrade $http_upgrade;
    proxy_set_header Connection "upgrade";

    proxy_redirect off;
    proxy_set_header   X-Forwarded-Proto $scheme;
}

ssl on;
ssl_certificate /etc/letsencrypt/live/xxx.com.au/fullchain.pem;
ssl_certificate_key /etc/letsencrypt/live/xxx.com.au/privkey.pem; 
}

www.yyy.com Server block: (Currently only serving welcome page)

server {
listen       80;
server_name  yyy.com www.yyy.com;

location /site {
  proxy_set_header X-Real-IP $remote_addr;
  proxy_set_header X-Forwarded-For $proxy_add_x_forwarded_for;
  proxy_set_header Host $http_host;
  proxy_set_header X-NginX-Proxy true;

  proxy_pass http://127.0.0.1:3002/;
  proxy_redirect off;
}
}

I have all the DNS set up and the host names set up on my droplet as well. I am using Vultr running Ubuntu if that helps.

I have added both via symbolic link to Sites-available and the line is present in the conf file.

EDIT: As Henry pointed out I was server /site


Solution

  • location /site {

    You're serving the app at /site and not /.

    You can map different different config blocks to different URLs, so you could e.g. route /example to a different node server if you wanted.

    Replacing location /site { with location / { as for your working block will serve your node application at the root. With no configuration for the root node nginx routes it to its default page.