nginx subdomain configuration on virtual host
Sub-domain configuration starts with an entry in the DNS server of the parent domain and the lookup resolves the sub-domain to an IP address of the web server. The web server in turn delegates the requests based on its configuration for the sub-domain.
If you don't have a DNS setup in your sub-domain, then the admin at example.com needs to set up a CNAME alias. The alias points the subdomain to the same web server, which hosts the website for the parent domain. The canonical names (CNAMES) are added for each of the subdomains. Once the subdomain is resolved to the IP address of the web server, the web server can route the request to a different website.
Comments
-
clwen almost 2 years
There are several questions on SO about nginx subdomain configuration but didn't find one that exactly the same as mine.
Say I got a virtual host
some.example.com
from higher-level net adminexample.com
at our organization. I want to usesome.example.com
as my primary site and usefoo.some.example.com
andbar.some.example.com
for auxiliary usage (proxy, etc). I tried this simple configuration and put it undersites-enabled
but didn't work:server { listen 80; server_name some.example.com; root /home/me/public_html/some; index index.html index.htm; } server { listen 80; server_name foo.some.example.com; root /home/me/public_html/foo; index index.html index.htm; } server { listen 80; server_name bar.some.example.com; root /home/me/public_html/bar; index index.html index.htm; }
In this setting
some.example.com
works fine, but for the other two browser return thatcould not find foo.some.example.com
. I'm running it on a ubuntu server.Is there something wrong with this configuration? Or is it something I should talk to higher level net admin (make
foo.some.example.com
andbar.some.example.com
to be registered)? -
clwen over 11 yearsThanks for replying. So I have two options: 1) build a DNS at
some.example.com
by my own 2) ask admin atexample.com
to addCNAME
s for two sub-domain mentioned? If I go with the latter, I will have to ask the admin atexample.com
every time I want to add a sub-domain? -
Brian Knight over 11 yearsYes - that's correct. In lieu of a separate DNS, all DNS requests would go to the DNS servers at example.com.
-
clwen over 11 yearsIf I choose to setup a DNS server by myself, I can point all the three domains in the example to the same IP, and let nginx to figure out which "server" (parent or foo or bar) to use?