So for whatever reason I always find myself having to look up how one makes virtual hosts in Apache. For you that don’t know what a virtual host is, it’s basically being able to host multiple DNS names via a single IP on a web server. Rather important unless A) you’re crazy B) you happen to have a nice swath of static IP addresses.
For the long version head over to the Apache site. Apache Virtual Host Documentation
The Short Virtual Host Configuration
Go ahead and edit your httpd.conf file with your favorite editor. Mine is VIM but I’m odd.
Where is my httpd.conf?
Well assuming you’re running Linux and in the case of RHEL distros it’s usually around:
I like to put my virtual host configurations near the bottom that way they are easy to find and keep track of.
CustomLog /var/log/httpd/your_website_access_log common
The above configuration will do a couple of things.
- It will make Apache respond to port 80 requests destined for your-website.com and www.your-website.com.
- Apache will serve up pages from /var/www/html/your-website-directory/.
- It will create a new error and access log at /var/log/httpd/ This is a nice to have if you’re going to host multiple websites and want an easy way to know what’s going on with each.
- The Directory statements will setup this virtual host for listening to .htaccess directives in the site should you need them. Ala what WordPress requires.
Issue a restart of httpd so that it reads in the new configuration, making sure it doesn’t complain. And that’s all there is to it.
For more details check out the following blog. http://www.jacmoe.dk/multiple-local-apache-virtual-hosts