Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

nginx subdomain configuration on virtual host

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 admin example.com at our organization. I want to use some.example.com as my primary site and use foo.some.example.com and bar.some.example.com for auxiliary usage (proxy, etc). I tried this simple configuration and put it under sites-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 that could 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 and bar.some.example.com to be registered)?

like image 698
clwen Avatar asked Jan 10 '13 00:01

clwen


1 Answers

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.

like image 161
Brian Knight Avatar answered Sep 20 '22 14:09

Brian Knight