Friday, April 23, 2010

Apache Virtual Host

The term Virtual Host refers to the practice of maintaining more than one server on one machine, as differentiated by their apparent hostname. For example, it is often desirable for companies sharing a web server to have their own domains, with web servers accessible as www.company1.com and www.company2.com, without requiring the user to know any extra path information.

Apache was one of the first servers to support IP-based virtual hosts right out of the box. Versions 1.1 and later of Apache support both, IP-based and name-based virtual hosts (vhosts). The latter variant of virtual hosts is sometimes also called host-based or non-IP virtual hosts.

Here is the example of how to add an virtual hosts entry in your httpd.conf (/etc/httpd/conf)


DocumentRoot /var/www/html/wwwsitefolder
#ServerName 192.168.0.99
ServerName www.domain.com
RewriteEngine On
RewriteRule ^/image/(.*)$Â /image.php?do=readfile&filepath=$1
SetEnvIfNoCase Request_URI \ \.(?:gif|jpg|jpe?g|png)$ no-gzip dont-vary
Header append Vary User-Agent env=!dont-vary
Header unset Pragma
FileETag None

Header set Cache-Control "max-age=2592000, must-revalidate"

CustomLog /var/log/httpd/test_access_log combined
ErrorLog /var/log/httpd/test_error.log

No comments:

Post a Comment