Red Hat Linux 7.2: The Official Red Hat Linux Customization Guide | ||
---|---|---|
Prev | Chapter 14. Apache Configuration | Next |
You can use Apache Configuration Tool to configure virtual hosts. Virtual hosts allow you to run different servers for different IP addresses, different host names, or different ports on the same machine. For example, you can run the website for http://www.your_domain.com and http://www.your_second_domain.com on the same Apache server using virtual hosts. This option corresponds to the <VirtualHost> directive for the default virtual host and IP based virtual hosts. It corresponds to the <NameVirtualHost> directive for a name based virtual host.
The Apache directives set for a virtual host only apply to that particular virtual host. If a directive is set server-wide using the Edit Default Settings button and not defined within the virtual host settings, the default setting is used. For example, you can define a Webmaster email address in the Main tab and not define individual email addresses for each virtual host.
Apache Configuration Tool includes a default virtual host as shown in Figure 14-8. Refer to the section called Default Virtual Host for details about the default virtual host.
The Apache documentation on your machine or on the Web at http://www.apache.org/docs/vhosts/ provides more information about virtual hosts.
To add a virtual host, click the Virtual Hosts tab and then click the Add button. The window as shown in Figure 14-9 appears. You can also edit a virtual host by selecting it in the list and clicking the Edit button.
The General Options settings only apply to the virtual host that you are configuring. Set the name of the Virtual Host in the Virtual Host Name text area. This name is used by Apache Configuration Tool to distinguish between virtual hosts.
Set the Document Root Directory value to the directory that contains the root document (such as index.html) for the virtual host. This option corresponds to the DocumentRoot directive within the VirtualHost directive. Before Red Hat Linux 7.0, Apache provided with Red Hat Linux used /home/httpd/html as the DocumentRoot. In Red Hat Linux 7.2, however, the default DocumentRoot is /var/www/html.
The Webmaster email address corresponds to the ServerAdmin directive within the VirtualHost directive. This email address is used in the footer of error pages if you choose to show a footer with an email address on the error pages.
In the Host Information section, choose Default Virtual Host, IP based Virtual Host, or Name based Virtual Host.
If you choose Default Virtual Host, Figure 14-10 appears. You should only configure one default virtual host. The default virtual host settings are used when the requested IP address is not explicitly listed in another virtual host. If there is no default virtual host defined, the main server settings are used.
If you choose IP based Virtual Host, Figure 14-11 appears to configure the <VirtualHost> directive based on the IP address of the server. Specify this IP address in the IP address field. To specify more than one IP address, separate each IP address with spaces. To specify a port, use the syntax IP Address:Port. Use :* to configure all ports for the IP address. Specify the host name for the virtual host in the Server Host Name field.
If you choose Name based Virtual Host, Figure 14-12 appears to configure the NameVirtualHost Directive based on the host name of the server. Specify the IP address in the IP address field. To specify more than one IP address, separate each IP address with spaces. To specify a port, use the syntax IP Address:Port. Use :* to configure all ports for the IP address. Specify the host name for the virtual host in the Server Host Name field. In the Aliases section, click Add to add a host name alias. Adding an alias here adds a ServerAlias directive within the NameVirtualHost Directive.
Note | |
---|---|
You can not use name based virtual hosts with SSL, because the SSL handshake (when the browser accepts the secure Web server's certificate) occurs before the HTTP request which identifies the appropriate name based virtual host. If you want to use name-based virtual hosts, they will only work with your non-secure Web server. |
If an Apache server is not configured with SSL support, communications between an Apache server and its clients are not encrypted. This is appropriate for websites without personal or confidential information. For example, an open source website that distributes open source software and documentation has no need for secure communications. However, an ecommerce website that requires credit card information should use the Apache SSL support to encrypt its communications. Enabling Apache SSL support enables the use of the mod_ssl security module. To enable it through Apache Configuration Tool you must allow access through port 443 under the Main tab => Available Addresses. Refer to the section called Basic Settings for details. Then, select the virtual host name in the Virtual Hosts tab, click the Edit button, choose SSL from the left-hand menu, and check the Enable SSL Support option as shown in Figure 14-13. The SSL Configuration section is pre-configured with the dummy digital certificate. The digital certificate provides authentication for your secure Web server and identifies the secure server to client Web browsers. You must purchase your own digital certificate. Do not use the dummy one provided in Red Hat Linux for your website. For details on purchasing a CA-approved digital certificate, refer to the Chapter 15.
The Site Configuration, Environment Variables, and Directories options for the virtual hosts are the same directives that you set when you clicked the Edit Default Settings button, except the options set here are for the individual virtual hosts that you are configuring. Refer to the section called Default Settings for details on these options.