How to configure multiple virtual hosts in apache

Source: Internet
Author: User


How to configure multiple virtual hosts in apache many users will not configure multiple virtual hosts in apache for testing on their local websites. Therefore, it is quite troublesome to test multiple websites. Today, I will release the previously configured code for you to learn. Test the configuration environment www.2cto.com OS: winxp sp3apache: Apache 2.2.10 for win. before configuring the configuration, describe that the ip address segment 127 used below is the playback address, that is to say, there is an independent ip address of 127.0.0.0-127.255.255.255, which can be used only locally, and the host file (win: C: \ WINDOWS \ system32 \ drivers \ etc) can be modified ), it is used to simulate Domain Name Pointing. The addresses all start with segment 127. Do not make a mistake! All configurations are modified in conf/httpd. conf under the apache directory. There are three methods to modify the virtual host configuration. The first method is to configure the Virtual Host Based on Multiple ip addresses. As the name suggests, it is to assign an ip address for each virtual directory, which involves modification: www.2cto.com 1) Port listening. All three configuration methods should be used. Think about it !! Not to mention Listen 802) the configuration section DocumentRoot of a VM "relative address of the VM directory or absolute address" ServerName IP address or domain name complete example # listener port setting Listen 80 # first VM DocumentRoot "D: \ wwwroot "ServerName 127.0.0.1: 80 # The second virtual host DocumentRoot" D: wwwroot2 "ServerName www.iiwnet.com Note: The second virtual host adds a simulated domain name ww.iiwnet.com, and the host needs to be modified, add a port listener pointing to 127.0.0.2 www.iiwnet.com. Modify 1 for a VM based on different ports of the same ip address, choose Listen 80 Listen 80802 according to your VM.) The configuration segment of a VM is DocumentRoot. "The relative or absolute address of the VM directory" ServerName IP address or domain name complete example # listener port settings Listen 80 Listen 8080 # First Virtual Host DocumentRoot "D: \ wwwroot" ServerName 127.0.0.1: 80 # second virtual host DocumentRoot "D: wwwroot2 "ServerName www.iiwnet.com Note: a simulated domain name www.iiwnet.com is added to the second VM. You need to modify the host and add a third Domain Name Pointing to 127.0.0.2 www.niutw.com, A virtual host based on the same ip address and the same port and different domain names, that is, a domain name-based virtual host (this is used more often) involves modification: www.2cto.com 1) Port Listening 1 Listen 802) this parameter must be set based on the domain name VM. Otherwise, the domain name cannot be interpreted. The official documentation explains how to specify an IP address (and port) for a domain name-based virtual host # modify the IP address NameVirtualHost 127.0.0.1: 803 here) A complete example of the ServerName domain name in the configuration section DocumentRoot "relative address or absolute address of the VM directory" ServerName # Listen 80 for the listening port # NameVirtualHost 127.0.0.1 for the domain name Virtual Host: 80 # First Virtual host DocumentRoot "D: \ wwwroot" ServerName www.iiwnet.com # second virtual host DocumentRoot "D: wwwroot2" ServerName www.niutw.com Note: host changes ww.iiwnet.com and www.niutw.com both point to 127.0.0.1

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.