So I just installed and configured Nginx 1.20.2 on my Digital Ocean Ubuntu 18.04 instance. I have purchased a domain through Namecheap, let's call it testdomain.io. I wanted to be able to access my Digital Ocean instance by visiting that domain name, so I configured it to use Digital Ocean's name servers and added the appropriate A records to get it to work. That all works just fine. What I'm trying to figure out now is how to host different subdomains on my Digital Ocean server so that if I visit app.testdomain.io it would take me to one site, and test.testdomain.io would take me to another. So now that I have Nginx running I tried to configure the appropriate sites-available configuration files and symlinked them to sites-enabled, but currently when I visit any of the subdomains they all just point to my main domain's index.html. Here are my configuration files
/etc/nginx/sites-available/app.testdomain.io
server {
listen 80;
root /var/www/nginx/app;
index index.html index.htm;
# If no server_name is defined in a server block then
server_name app.testdomain.io;
location / {
# Return a 404 error for instances when the server receives
try_files $uri $uri/ =404;
}
}
/etc/nginx/sites-available/test.testdomain.io
server {
listen 80;
root /var/www/nginx/test;
index index.html index.htm;
# If no server_name is defined in a server block then
server_name test.testdomain.io;
location / {
# Return a 404 error for instances when the server receives
try_files $uri $uri/ =404;
}
}
My main configuration file:
server {
listen 80;
server_name localhost;
#access_log /var/log/nginx/host.access.log main;
location / {
root /var/www/nginx/;
index index.html index.htm;
}
}
Regardless of when I visit app.testdomain.io, test.testdomain.io, or testdomain.io they all visit the main root index.html.