Search Perform an advanced search query SOFTPEDIA
 
SOFTPEDIA
Updated one minute ago
HomeSubmit a program for being reviewedAdvertise on our websiteGet help on surfing our websitesSend us your feedbackGet information about our XML/RSS backend and how to use itBrowse the news archiveVisit our discussion forumVizitati forumul in limba romana



KLIP
  1. HOME
  2. SCIENCE
  3. TECHNOLOGY
  4. WEBMASTER
  5. SECURITY
  6. MICROSOFT
  7. LINUX
  8. APPLE
  9. GAMES
  10. TELECOMS
  11. REVIEWS
  12. LIFE & STYLE
  13. EDITORIALS
  14. INTERVIEWS
  15. RSS
Welcome!
Hello, Guest

Login if you have a Softpedia.com account.

Otherwise, register for one.

OTHER TIPS, TRICKS AND TUTORIALS

Apache VirtualHosting Guide

- Hosting several websites on the same IP address.

By: Mihai Marinof, Linux Editor

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

<VirtualHost *:80>
ServerName www.yourdomain.com
DocumentRoot /var/www/html/
</VirtualHost>

<VirtualHost *:80>
ServerName webmail.yourdomain.com
DocumentRoot /var/www/webmail
</VirtualHost>


- 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

<VirtualHost *:80>
ServerName webmail.yourdomain.com
DocumentRoot /var/www/webmail
ErrorLog /var/log/httpd/webmail-error_log common
CustomLog /var/log/httpd/webmail-access_log common
</VirtualHost>


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.

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
 
Comments | Link here | Subscribe
Print | Send to friend
Today's News | Yesterday's News

Search:

24th November 2006, 11:28 GMT | Copyright (c) 2006 Softpedia | Contact:
Read by 4,295 user(s) | Rating: | 6 vote(s) so far | Cast your vote:
Apache VirtualHosting Guide - USER OPINIONS




We are sorry, there are no opinions available for this article.






SHARE YOUR OPINION ABOUT Apache VirtualHosting Guide

Since you are not logged on, your comments will have to be approved before being displayed.
Click here to login, or register.
Your Name:
Your Email:
Type in the result:
Your Opinion:
 


DO YOU WANT TO CONTACT US?  

If you have some comments or you want to send us some information you can send us an email directly to .
You can use the form below for the same purpose.
Your full name: (at least 3 characters)
Your email address: (at least 5 characters)
Message subject: (at least 5 characters)
Message text:
(at least 10 characters)
Type in the result:
 
 



© 2001 - 2008 Softpedia. All rights reserved.
Softpedia™ and Softpedia™ logo are registered trademarks of SoftNews NET SRL.
Copyright Information | Privacy Policy | Terms of Use | Contact Softpedia | Update your software | Archive