NEWS CATEGORIES:



NEWS ARCHIVE >>
SOFTPEDIA REVIEWS >>
MEET THE EDITORS >>
Home > News > Linux > Other Tips, Tricks and Tutorials

Other Tips, Tricks and Tutorials


Apache VirtualHosting Guide

Hosting several websites on the same IP address.

By Mihai Marinof, Linux Editor

24th of November 2006, 11:28 GMT

Adjust text size:


Virtual Hosts refers to Apache's ability to host several websites on the same machine and even on the same IP address. For instance, let's say that you have a small website, www.yourdomain.com, which also provides free email accounts to your visitors. Of course, you will also have to set up a webmail so your visitors can actually use the email address created on your site. You could very easily set up the webmail to be accessible from the address www.yourdomain.com/webmail, but for both aesthetic and practical reasons, the webmail service could be found at webmail.yourdomain.com. Moreover, you can set up as many virtual hosts as you want, on a single IP address.

- The virtual hosts can be defined and configured in Apache's config file. This config file can be found in Fedora Core by default in /etc/httpd/conf/httpd.conf but the location of this file may vary on other distributions.

- Once found, open it with your favorite text editor and search for the NameVirtualHost.

Make sure it looks like this (and it's not commented out):
CODE
NameVirtualHost *:80

NOTE: The following example will require you to have the main website located in /var/www/html and the new webmail will be installed in /var/www/webmail. If your locations vary, change the example accordingly, before adding them to httpd.conf.

- To get it up and running quickly, add these lines at the end of httpd.conf:
CODE

ServerName www.yourdomain.com
DocumentRoot /var/www/html/



ServerName webmail.yourdomain.com
DocumentRoot /var/www/webmail


- If you want more advanced virtual host configuration, you can use any of the following directives:

Logging

- By default, Apache will record messages to access_log and error_log files located in /var/log/httpd. However, if you want each virtual host to have its own separate logs, add these directives to the virtual host block:
CODE
ErrorLog /var/log/httpd/website1-error_log common
CustomLog /var/log/httpd/website2-access_log common

- For example, if you want your webmail site to record messages to files webmail-access_log and webmail-error_log, then your vhost block for webmail site will look like this:
CODE

ServerName webmail.yourdomain.com
DocumentRoot /var/www/webmail
ErrorLog /var/log/httpd/webmail-error_log common
CustomLog /var/log/httpd/webmail-access_log common


Error Pages

- You can set Apache to serve a custom page when a visitor gets a 404 (not found) or 500 (internal server error) or any other error code, for that matter. For instance, you can redirect a visitor which received a 404 error to the main index file, or to a 404 file you created. For this, you'll have to add the following directives to the virtual host block, just like in the above example:
CODE
ErrorDocument 404 /index.htm
ErrorDocument 500 /index.htm

NOTE: The error page could be anything; but remember: the location starts with the directory set in DocumentRoot in httpd.conf. For instance, if your DocumentRoot is /var/www/html and the error page is in /var/www/html/messages/404.htm, then you'll have to append /messages/404.htm to the ErrorDocument directive.

Server Aliases

- If you want to use your virtual host for more than one domain name, you can put ServerAlias directive inside the virtual host block in order to link the two domains together:
CODE
ServerAlias youdomain.com yourseconddomain.com

Further directives can be found on Apache's documentation page. Don't be afraid to experiment with httpd.conf, but always remember to back it up first before any reconfiguration.

Read by 5,650 user(s) | Add comment | Link to this article TWEET THIS


Article rating:
Good (3.0/5) 6 vote(s)    

Subscribe to news | Print article | Send to friend

© Copyright 2001-2010 Softpedia
Contact:

 

 

SEARCH THE NEWS ARCHIVE :




Today's News
| Yesterday's News | News Archive


MORE RELATED ARTICLES:


Building Your Own IRC Server with Services

Resetting a Forgotten Root Password

How to Setup a Free Backup Solution for MySQL

How to Get Connected to the IPv6 Internet

How to Install Java in Fedora Core 6

Debian Installation Guide

Installing A Linux Distro to An USB Drive

User opinions:

No user comments yet.
Be the first to express your opinion using the form below!

Share your opinion:

Your Name:
Your Email Address:
(will not be used for commercial purposes)
Solve this to prove you're not a bot: =
Your review/opinion:

 




Windows tabGames tabDrivers tabMac tabLinux tabScripts tabMobile tabHandheld tabGadgets tabNews tab

SUBMIT PROGRAM   |   ADVERTISE   |   GET HELP   |   SEND US FEEDBACK   |   RSS FEEDS   |   ENTER NEWS SITE   |   ENGLISH BOARD   |   ROMANIAN FORUM