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.

These answers are provided by our Community. If you find them useful, show some love by clicking the heart. If you run into issues leave a comment, or add your own answer to help others.

×
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.

Submit an Answer