Step One: Name Resolution
Usually name resolution is done by a DNS server. This server takes a URL like "www.thecuriousdreamer.com" and returns an IP number (the Internet Protocol address is actually a number, but we humans find numbers more difficult to remember than text addresses). In addition to the DNS server, the operating system has a text file that can be used to resolve URLs.I need my operating system (Linux in my case) to resolve URLs that I specify to my machine's IP number. This is very easy. I just need to edit the file called "/etc/hosts" to add the names I want to resolve. In this file I found an entry for “localhost” which is standard name for the default Apache web server on a local machine. The entry was:
127.0.0.1 localhost
As my machine came, typing “http://localhost” into a web browser would serve up documents in the standard web server on the machine. So I added a couple of lines to the hosts file so this part of it no read:
127.0.0.1 localhost
127.0.0.1 my.thecuriousdreamer.com
127.0.0.1 my.andrewault.net
I needed to be root to be able to edit and save the hosts file.
Step Two: Setting up a Virtual Server
I found that Apache will handle virtual servers easily. You just need to modify one setup file called "\etc\apache2\httpd.conf". I found the section for virtual hosts in httpd.conf and added a few more lines. I read about virtual hosting on the Apache site. I learned that the first virtual host that is specified is used by default in case the URL is not resolved by Apache. I wanted to use the existing directory in this case. I added the following lines to the httpd.conf file:<virtualhost>
DocumentRoot /home/andrewault/public_html/
</virtualhost>
<virtualhost>
DocumentRoot /home/andrewault/public_html/www.thecuriousdreamer.com
ServerName my.thecuriousdreamer.com
</virtualhost>
<virtualhost>
DocumentRoot /home/andrewault/public_html/www.andrewault.net
ServerName my.andrewault.net
</virtualhost>
The first block of code makes the existing server the default virtual server. The next two blocks each add a new virtual server. Note that I use the target URL except that instead of “www” I use”my”. This allows be to keep the same name and keep my system organized.
Notes: You have to restart Apache for these changes to be effected. I just stopped and restarted the Apache daemon, but you could just restart the computer. Also, as with the hosts file, you need to be root to edit the httpd.conf file.
No comments:
Post a Comment