Forum Moderators: phranque
1) Point *.domain.com to my server
2) Point only listed entires such as www.domain.com at my server.
I'm asking because I'm trying to get some sub-domains set up eg. sub1.domain.com, sub2.domain.com
However, when sub1.domain.com is resolved, it gets as far as the DNS host and then stops as there is no entry.
Should this happen?
Is there a way to get *.domain.com to point to my server or do I have to ask for an entry for each of the sub domains?
Once at the server, the sub domains can be distinguished, I just need to get them to the server...
*.domain.com allows unlimited sub domains but they will all resolve to the root directory of the main domain. For sub-domains to resolve to different directories individual entries would be required.
Sugarkane,
> eg www.domain and *.domain resolve to one IP,
> mail.domain to another and secure.domain to a different one
IMHO it is not possible to mix *.domain.com and mail.domain or any other sub.domain using named or IP based VirtualHosts. I did some experimenting and could not get sub.domain to resolve to a separate directory one my Linux/Apache dedicated server.
If secure.domain is meant to be an SSL sub-domain it would work because SSL normally has separate VirtualHost entries and a different port, usually 443.
====================
Example entries in zone file for using *.domain.com
www IN A 22.22.22.199
ftp IN A 22.22.22.199
mail IN A 22.22.22.199
* IN CNAME domain.com.
*.domain.com also needs to be added to the VirtualHost directive in httpd.conf to work. For example
<VirtualHost 22.22.22.199>
ServerName domain.com
ServerAlias *.domain.com
DocumentRoot /home/example/htdocs
..
..
</VirtualHost>
------------------------
Example zone file entries using separate sub domains
www IN A 22.22.22.199
ftp IN A 22.22.22.199
mail IN A 22.22.22.199
; Sub domain entries
sub1 IN A 22.22.22.199
sub2 IN A 22.22.22.250
Separate VirtualHost entries are required in httpd.conf for each sub domain as shown in examples below.
<VirtualHost 22.22.22.199>
ServerName sub1.domain.com
DocumentRoot /home/example/sub1
..
..
</VirtualHost>
<VirtualHost 22.22.22.250>
ServerName sub2.domain.com
DocumentRoot /home/example/sub2
..
..
</VirtualHost>
NameVirtualHost 192.168.100.1
<VirtualHost 192.168.100.1>
ServerName www.domain.net
DocumentRoot /home/www
</VirtualHost>
<VirtualHost 192.168.100.1>
ServerName sub1.domain.net
DocumentRoot /home/www/sub1
</VirtualHost>
Requests to sub1 would go to /home/www/sub1, requests for www or sub2 (or whatever) would go to /home/www
I've not found a way to get this working with multiple domains - like you say, I'm not sure it's possible.
What I was wondering was, can you have a mix of named and wildcard subdomains on the DNS server? My mail server is on x.x.x.203, my webserver on x.x.x.201
Can it be set so that mail.domain resolves to 203 but anything else goes to 201?
After a little bit more experimenting I figured out how to use named and wildcard sub-domains for any domain hosted on an Apache Server.
The solution is to use named virtual hosts and put every named.domain.com above domain.com in httpd.conf
Also make sure the wildcard is the last entry in the domain zone file.
When a request is received, Apache finds the named sub.domain before reaching the wildcard and resolves to the correct directory. It even works on a shared IP without problems.
Example of zone file entries
----------------------------
IN MX 10 mail
www IN A x.x.x.201
ftp IN A x.x.x.201
mail IN A x.x.x.203
; Additional sub domains
sub1 IN A x.x.x.201
sub2 IN A x.x.x.201
; When adding sub domains make sure the * is the last line
* IN CNAME domain.com.
; Note the dot after domain.com is required
Make sure all the named sub domain VirtualHosts appear above the wildcard VirtualHost
Virtual host entries in httpd.conf
----------------------------------
NamedVirtualHost x.x.x.201
# NamedVirtualHost x.x.x.203
# Uncomment above line to use x.x.x.203 for named virtual hosts.
<VirtualHost sub1.domain.com>
ServerName sub1.domain.com
DocumentRoot /path/to/sub1
.....
</VirtualHost>
<VirtualHost sub2.domain.com>
ServerName sub2.domain.com
DocumentRoot /path/to/sub2
.....
</VirtualHost>
<VirtualHost domain.com>
ServerName domain.com
ServerAlias *.domain.com
DocumentRoot /path/to/html
....
</VirtualHost>