Score:0

How should I set my nginx configuration to use subdomains with CNAME host record?

cn flag

running Debian 11.

How should I add my subdomain to my site using my CNAME DNS records? My website directory is located at /var/www/ and I'm wondering if I can make a subdirectory for the subdomain within that directory.

i.e. /var/www/domain-dir/subdomain-dir

Can I add subdomain server_name to right in my sites-available config file?

I don't want to create tons of A/AAAA records to point to my subdomain as it could become messy as I'll likely create more subdomains later, blog.example.com, git.example.com, etc..

Sorry if this post is long, I'm new to this and don't know how to make it more concise!

Score:1
us flag

The actual directory in nginx can be anything, you just need to set the root directive properly in the virtual host for the subdomain.

I would advice to have a completely separate directory for each virtual host, for example:

/var/www/example.com
/var/www/sub.example.com

If you have subdomain files at /var/www/example.com/subdomain directory, you might have duplicate content issues, since the same content would be available at http://sub.example.com and http://example.com/subdomain.

Score:0
ie flag
  1. Add the sub domains as entries in the same server config file and point the sub domains to the specific file path containing the sub domains files. Creating a sub directory should work. https://stackoverflow.com/questions/17568981/nginx-two-subdomain-configuration

  2. Update cnames with your dns provider.

You can use nginx -t to check the syntax in you files.

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.