I am slogging through getting two domains to properly served through NGINX, on digitalocean.com hosting (in a Ubuntu 20,04 Droplet). Let's call them domain1.com (default) and domain2.com. domain1.com is working properly and has SSL (from Let's Encrypt), domain2 is just http at this point.
The home page of domain2.com loads fine now, using this server block:
server {
listen *:80;
listen [::]:80;
root /home/domain2/;
index index.html;
server_name domain2.com www.domain2.com;
location / {
try_files $uri $uri/ =404;
}
}
However, when I navigate to a different page on the domain2.com site, it loads the default site domain1.com. Quite odd to see domain2.com in the Chrome address line with domain1.com web pages coming up.
I assume this has something to do with domain1.com being default but I don't know why this is happening. I'm pretty novice at NGINX... what should I do to fix this?
The default file in /etc/nginx/sites-available has this content:
server {
listen 80 default_server;
listen [::]:80 default_server;
root /home/domain1/server/public;
index index.js index.html index.htm index.nginx-debian.html;
server_name localhost;
location / {
proxy_pass http://localhost:5000;
proxy_http_version 1.1;
proxy_set_header Upgrade $http_upgrade;
proxy_set_header Connection 'upgrade';
proxy_set_header Host $host;
proxy_cache_bypass $http_upgrade;
}
}
server {
root /home/domain1/server/public;
index index.js index.html index.htm index.nginx-debian.html;
server_name domain1.com; # managed by Certbot
location / {
proxy_pass http://localhost:5000;
proxy_http_version 1.1;
proxy_set_header Upgrade $http_upgrade;
proxy_set_header Connection 'upgrade';
proxy_set_header Host $host;
proxy_cache_bypass $http_upgrade;
}
listen [::]:443 ssl ipv6only=on; # managed by Certbot
listen 443 ssl; # managed by Certbot
ssl_certificate /etc/letsencrypt/live/intraprem.com/fullchain.pem; # managed by Certbot
ssl_certificate_key /etc/letsencrypt/live/intraprem.com/privkey.pem; # managed by Certbot
include /etc/letsencrypt/options-ssl-nginx.conf; # managed by Certbot
ssl_dhparam /etc/letsencrypt/ssl-dhparams.pem; # managed by Certbot
}
server {
if ($host = domain1.com) {
return 301 https://$host$request_uri;
} # managed by Certbot
listen 80 ;
listen [::]:80 ;
server_name domain1.com;
return 404; # managed by Certbot
}