Subdomains
I'm looking into setting up subdomains on my site & was really after some pointers.
Can I just edit apache's config to point the subdomain to a set directory or will I need to mess about with DNS?
Apologies for the noob posting!
Fully.
11 Replies
You will need to set another vhost is the apache conf file and then add an A record to the DNS record.
Adam
If you don't really know too much about DNS, check to see if your registrar supports subdomains .. or your current domain name service provider supports them. (like a web-interface or something)
If they don't, transfer your DNS to zoneedit.com (great and free), and then can easily deal with subdomains and such.
Basically you need to create a subdomain and point it to an IP.
After you have done such, you need to setup apache to deal with subdomains (the following is an example)
#
# Use name-based virtual hosting.
#
NameVirtualHost 12.13.14.15
<virtualhost 12.13.14.15="">ServerAdmin webmaster@domain.com
DocumentRoot /usr/www/htdocs
ServerName sub.domain.com
ServerAlias www.sub.domain.com
ErrorLog /usr/www/logs/error_log
CustomLog /usr/www/logs/access_log common
UserDir enabled jack
# this would be for something like http://sub.domain.com/~jack</virtualhost>
HTH
Sunny Dubey
caker++
Thanks for all the advice guys. Looks like the * bit in my dns was all I needed
Weird how I didn't use that in the Cpanel account I run yet subdomains came online instantly.. sounds like Voodoo to me
Thanks again.
Fully
Meaning if I were to go to: kjsht5.domain.com or w24ksrg.domain.com I will get the first virtual host apache is serving up.
Therefore it is suggested that first virtual host be a dummy virtual host, which an error of "Domain not configured" or something similar. httpd -S will show you how your virtual hosts are configured.
Sunny Dubey
I maybe off base. Just trying offer alittle bit help back to you guys.
Sorry if i wrong giving out bad advise(my bust).
First of all, know that Reverse DNS lookups are a specific kind of DNS lookup, and that they have absolutely nothing to do with making web server vhosts work. I'll explain more about what they are good for at the end.
You can configure your web server with all the vhosts you want. A vhost for
Right now, let's pretend that I have my web server configured with a vhost for
Right now, I actually do have a vhost for http://state.gov.zz/
So in order for web browsers to find your web server, the name has to exist in DNS, and it has to resolve to your IP address. Once that's all set, your web server will actually receive connections when people enter the name into their browsers.
Now let's look at the opposite situation. Let's say you've got DNS all set up, and your web server is running, but you don't have a vhost for the name. What happens when a browser requests something from that website? Your web server has to send something, so what it does is it searches the list of vhosts, finds that none match, and then goes back to the first one on the list and serves the content from that vhost. That's why people like me always create a default vhost and put it first in the configuration, and then create subsequent vhosts for each real domain that the server is supposed to serve.
Basically, in order for a web server virtual host to work, both need to be set up.
Now, Reverse DNS is a different business. It's generally only used for logging or displaying client connections. For example, if you were to run a web browser on your linode and connect to my web server, my web server would have your IP address. However, my web server will try to do a reverse lookup to get the hostname, so that it can write that to the log instead of the IP address. The same sort of thing happens when you connect to IRC. The IRC server does a reverse lookup to get your hostname as uses that in your hostmask instead of the IP address. Having reverse DNS set to your own hostname vs. the default generally doesn't actually make anything work any differently. There are exceptions, but you can safely ignore them.