Redhat: Apache webserver Virtual Hosts

From Define Wiki
Revision as of 10:41, 25 August 2013 by Michael (talk | contribs) (Created page with "== Virtual Hosts == Apache allows multiple websites to be hosted on the same system. This is useful given the limited number of IPv4 IP address available. This is done throu...")
(diff) ← Older revision | Latest revision (diff) | Newer revision → (diff)
Jump to navigation Jump to search

Virtual Hosts

Apache allows multiple websites to be hosted on the same system. This is useful given the limited number of IPv4 IP address available. This is done through virtual hosts that are defined in the httpd.comf file.

Regular Virtual Hosts

The first directive that must be enabled is:

NameVirutalHost *:80

To use name based hosts leave the asterisk after the directive. Otherwise set the IP address for the local interface.

Port 80 is the default port of web pages. To direct all requiests via IP 192.168.122.50 on port 80, the virtual host would be defined as shown. But in most cases you would use the above directive so that all websites. It also allows DHCP to work.

<VirtualHost 192.168.122.50:80>


Example Virtual Hosts

<VirtualHost *:80>
       ServerAdmin webmaster@boston1.example.com
       DocumentRoot /www/docs/boston1.example.com
       ServerName boston1.example.com
       ErrorLog logs/boston1.example.com-error_log
       EustomLof logs/boston1.example.com-error_log common
</VirtualHost>
<VirtualHost *:80>
       ServerAdmin webmaster@boston2.example.com
       DocumentRoot /www/docs/boston2.example.com
       ServerName boston2.example.com
       ErrorLog logs/boston2.example.com-error_log
       EustomLof logs/boston2.example.com-error_log common
</VirtualHost>

For the first Virtual Host:

  • Error messages are emailed to webmaster@boston1.example.com
  • Webpages are stored in teh DocumentRoot
  • Clients call the websire through the server name
  • The logs are sent to the paths relative to the Serverroot

Syntax Check

To check the syntax of the httpd.conf file run:

httpd -t
Syntax OK

Check Virtual Hosts

httpd -S
httpd -D DUMP_VHOSTS

Secure Virtual Hosts

SSL Certificates