Wildcard subdomains

Every vhost or domain on MageStack is configured with a wildcard and www server alias - so if you have a vhost example.com, nginx will serve the content for example.com, www.example.com, and *.example.com.

This lets you create subdomains without creating new vhosts for them - if a subdomain has DNS pointing at your stack, MageStack maps it to a directory of the same name inside your domain's directory.

How it works

If we imagine a domain example.com, the domain directory looks similar to the following:

/domains/example.com/
http/ <- docroot for example.com and www.example.com (http/pub for Magento 2)
___general/ <- system directory
___maintenance/ <- system directory
___rewrites/ <- system directory

To create blog.example.com, you'd then:

  • Create the directory /domains/example.com/blog and add content to it
  • Add an A record for blog.example.com to point to your stack

Note - if your vhost is configured as type Magento 2, subdomains will inherit this, so the doc root would be /domains/example.com/blog/pub instead of /domains/example.com/blog.

Any directory can become a live subdomain with wildcard DNS set

If you have a wildcard DNS record set (*.example.com pointing at your stack), then any directory you create under /domains/example.com/ is then reachable as a subdomain without any extra config.

So if you create /domains/example.com/backup to keep a copy of previous data, backup.example.com would become live and start serving content from that directory.

If you need to keep files under your domain directory that you don't want to be served, either avoid wildcard DNS records, or prefix the directory name with underscores - _backup can't be served, as _ isn't a valid character in a hostname. This is why the default configuration directories in a vhost path are named ___general, ___rewrites and ___maintenance (in theory 1 _ is fine, but we use 3 just to try to make it a bit clearer).

Disabling wildcard subdomains

If you'd rather subdomains only work when explicitly set up as extra vhosts instead, we can disable this wildcard behaviour for your stack - please just let us know with a ticket.

Once disabled, only example.com and www.example.com are served for a vhost example.com, and any other subdomain would need creating as its own vhost in the control panel first.