Score:0

Configuring virtual host subdomains on a Digital Ocean server using Nginx

am flag

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.

djdomi avatar
za flag
did you reload the nginx service?
jc137 avatar
am flag
Yep, I did nginx -s reload multiple times throughout the setup
djdomi avatar
za flag
i would add to each site an access and error log so that you see which is triggerd, moreover nginx -t does not gaave any errors?
mangohost

Post an answer

Most people don’t grasp that asking a lot of questions unlocks learning and improves interpersonal bonding. In Alison’s studies, for example, though people could accurately recall how many questions had been asked in their conversations, they didn’t intuit the link between questions and liking. Across four studies, in which participants were engaged in conversations themselves or read transcripts of others’ conversations, people tended not to realize that question asking would influence—or had influenced—the level of amity between the conversationalists.