Score:0

Nginx to point to different subdomains

fr flag

I have a domain (example.com) that I am trying to use subdomains to show different parts of the applications. Right now is all Hosted in AWS.

This is sort of the set up I am trying to go for.

sbx.example.com trn.example.com office.example.com

My nginx conf right now is as follow:

    server {
        listen 80;
        root /var/www/html/apt-front/dist;
    
        # Add index.php to the list if you are using PHP
        index index.html index.htm index.nginx-debian.html;
    
        server_name example.com www.example.com;
    
             location / {
                try_files $uri $uri/ /index.php$is_args$args;
             }
    
        location /api{
          alias "/var/www/html/api/public";
          try_files $uri $uri/ @api;
              location ~ \.php$ {
                fastcgi_split_path_info ^(.+\.php)(/.+)$;
            fastcgi_pass unix:/var/run/php/php7.4-fpm.sock;
                    fastcgi_index index.php;
                    include fastcgi_params;
                    fastcgi_param SCRIPT_FILENAME /var/www/html/mint-api/public/index.php;
        }
         }
    
           location @api {
                rewrite /api/(.*)$ /api/index.php?/$1 last;
           }
    
    
        include /etc/nginx/sites-available/*.conf;

}

I know that in AWS i would need to create a record for the domain, i believe that would be a NS record with the name of the subdomain (such as sbx.example.com). What I was thinking of doing is creating another repository (a clone) with the changes that i need for SBX, create another server block and under server name just change the subdomain? Thoughts?

Ginnungagap avatar
gu flag
What's the question? See [How do I ask a good question?](https://serverfault.com/help/how-to-ask)
Score:0
cn flag

I know that in AWS i would need to create a record for the domain

Yes, in any DNS you'd have to.

i believe that would be a NS record with the name of the subdomain

This would be a "A" record. This will point your Name (Domain) to your host (IP). "NS" ist for "Nameservers".

(such as sbx.example.com)

Exactly. Like this:

sbx.example.com. 1800  IN  A    127.0.0.172

Then just redirect the subdomain's request to the folders (or URIs) you need.

Score:0
gp flag
Tim

Not difficult, but there's a few steps

  • Create your Route53 hosted zone
  • Register your domain, enter the R53 name servers
  • Create A record for the main domain
  • Create CNAME records for each subdomain, pointing at the main domain
  • Nginx is configured to respond to each of the domains. That they are subdomains is irrelevant to Nginx.
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.