Split-server{ } subdomains

Hi,

Can i have:

server{
listen 80;
server_name domain.com www.domain.com;
root /dir1;
}
server{
listen 80;
server_name sub.domain.com;
root /dir2;
}

Without adding an A-record for sub.domain.com’s DNS?

TIA,
Nuno

2009/9/8 Nuno Magalhães [email protected]:

Without adding an A-record for sub.domain.com’s DNS?

You need a wildcart in DNS, A-record or CNAME for *.domain.com.

Yes, because nginx isn’t needing the name to resolve to different
locations.

Your DNS zones should send all request to X ip address.
Then nginx will just read in the HOST header from the http request and
load the appropriate server entry from your configuration.

Does that make sense?

David M.

Hello!

On Tue, Sep 08, 2009 at 10:40:51PM +0100, Nuno Magalhães wrote:

listen 80;
server_name sub.domain.com;
root /dir2;
}

Without adding an A-record for sub.domain.com’s DNS?

Yes. Server_name is just string that will be matched on ‘Host’
header got in request. It doesn’t matter if this string is valid
domain name or not.

Maxim D.

Thanks David and Maxim.

On Tue, Sep 8, 2009 at 22:50, Grzegorz S.[email protected] wrote:

You need a wildcart in DNS, A-record or CNAME for *.domain.com.

I have 3 a-records at the moment: domain.com, www.domain.com,
sub.domain.com (i guess these two could maybe be replaced by cname).
I assumed domain.com would be the same as *.domain.com, but i guess
not.

If i set *.domain.com, i assume nginx will redirect
nonexistant.domain.com to the default server or, if no default is set,
to the first one that matches… would that be domain.com or the first
alphabetical subdomain?