marti149
By:
marti149

Can I have 2 DNS name's point to different folders in one droplet?

April 8, 2017 443 views
DNS Nginx Ubuntu

I installed NGINX and have a pretty much static pages. I want to point my DNS hostname to a subdirectory and one to the main top directory.
Is is possible to do this on digitalocean?

Testing out if its possible to switch over to digital ocean.

1 Answer

Hi @marti149

I'm not sure if I understand what you're trying to do, but my answer would be yes :-)

So you want to do something like this?

www.mydomain.com       would point to /var/www/website
www.otherdomain.com    would point to /var/www/website/subdir
  • yes! Exactly what I am trying to do. Where is there a tutorial or key word to search on how to set this up?

    • @marti149

      I would recommend setting up multiple server blocks. If you already have one working for the primary domain, you can use it as a basis as not much needs to be changed.

      When it comes to setting up domains, the primary two directives that you'd need to change would be server_name and root. The first defines what domain, or sub-domain, a request is processed for and the second defines the web root for said domain or sub-domain.

      So if you have:

      server {
          listen 80;
          listen [::]:80;
          server_name domain.com www.domain.com;
      
          root /path/to/domain.com/;
      
          location / {
              try_files $uri $uri/ /index.html;
          }
      }
      

      You'd simply take that and change it over to:

      server {
          listen 80;
          listen [::]:80;
          server_name sub.domain.com www.sub.domain.com;
      
          root /path/to/sub.domain.com/;
      
          location / {
              try_files $uri $uri/ /index.html;
          }
      }
      

      Or if you wanted to add another domain:

      server {
          listen 80;
          listen [::]:80;
          server_name domain2.com www.domain2.com;
      
          root /path/to/domain2.com/;
      
          location / {
              try_files $uri $uri/ /index.html;
          }
      }
      

      That's just basic configuration though and will only support HTML files. If you need to use PHP, proxy to a NodeJS application, etc, then there would be slightly more configuration needed.

Have another answer? Share your knowledge.