The Apache virtual host configuration can be divided into three types: port based, ip-based, and domain-based virtual hosts. Let's make a brief introduction to each of the following.
Let's take the Httpd-2.2.21-win32-x86-no_ssl.msi version under the Windows platform for example. One, port based virtual host settings
1. Modify the Listening port
Open the Apache profile httpd.conf and add the listening port you want to use
Such as:
Listen
Listen Bayi
Listen 82
The above setting means listening for 80, 81, 82 ports (note that there is no conflict with other software ports).
2, change the virtual host settings:
Open the Apache configuration file httpd.conf, look for include conf/extra/httpd-vhosts.conf, and remove the front # number.
Modify the virtual host configuration file apache/conf/extra/httpd-vhosts.conf, clear or comment out all original content, place the following content
<virtualhost *:80>
documentroot "d:/wamp/www"
</VirtualHost>
<virtualhost *:81>
documentroot "D:/wamp/test1"
</VirtualHost>
<virtualhost *:82>
documentroot "d:/" Wamp/test2 "
</VirtualHost>
3, testing:
Open the browser to enter http://localhost, http://localhost:81, http://localhost:82 access to different Web sites two, ip-based virtual host Settings
An ip-based virtual host is a different IP address configured for each Web site. It is typically used for WEB servers with multiple physical network adapters or multiple virtual IP configurations.
A network adapter binds multiple IP addresses, opens Control Panel-> network Connection-> Local Area Connection-> "Right-click Properties"-> from the General tab Find Internet Protocol (TCP/IP)-> "click Properties"-> Click the "Advanced" button below, the "Add" button under "IP Settings-ip address" in Advanced, enter the IP address you want to bind. If the IP address for the local connection is 192.168.1.2, continue adding 192.168.1.3, 192.168.1.4, 192.168.1.5, and so on. Use these IP to differentiate between different virtual hosts.
We are not bound here, because all 127 of the beginning points to this machine, such as 127.0.0.1 ~ 127.0.0.255 and so on. So we do the tests with these addresses. These addresses can only be accessed on the local computer.
1. Specify the Listening port
To open the Apache profile httpd.conf, specify the listening port
Such as:
Listen 80
The above setting means listening to port 80.
2, change the virtual host settings:
Open the Apache configuration file httpd.conf, look for include conf/extra/httpd-vhosts.conf, and remove the front # number.
Modify the virtual host configuration file apache/conf/extra/httpd-vhosts.conf, clear or comment out all original content, place the following content
<virtualhost 127.0.0.1:80>
documentroot "d:/wamp/www"
ServerName 127.0.0.1:80
>
<virtualhost 127.0.0.2:80>
documentroot "D:/wamp/test1"
ServerName 127.0.0.2:80
</ virtualhost>
<virtualhost 127.0.0.3:80>
documentroot "D:/wamp/test2"
ServerName 127.0.0.3:80
</VirtualHost>
3, testing:
Open the browser to enter http://127.0.0.1, http://127.0.0.2, http://127.0.0.3 access to different Web sites three, domain-based virtual host settings
1, modify the Hosts file
For example, in WINDOWS 2003, there is a hosts file under C:\WINDOWS\system32\drivers\etc.
This hosts the role is to some commonly used URL domain name and its corresponding IP address, when users enter a Web site in the browser, the system will first automatically find the corresponding IP address from the Hosts file, once found, the system will immediately open the corresponding Web page, if not found, Then the system will submit the URL to DNS domain name resolution server for IP address resolution.
Open the Hosts file, there are generally "127.0.0.1 localhost", add the domain name you want to increase, as follows:
127.0.0.1 www.test.com
127.0.0.1 www.test1.com
127.0.0.1 www.test2.com
2. Specify the Listening port
To open the Apache profile httpd.conf, specify the listening port
Such as:
Listen 80
The above setting means listening to port 80.
3, change the virtual host settings:
Open the Apache configuration file httpd.conf, look for include conf/extra/httpd-vhosts.conf, and remove the front # number.
Modify the virtual host configuration file apache/conf/extra/httpd-vhosts.conf, clear or comment out all original content, place the following content
Namevirtualhost *:80
<virtualhost *:80>
documentroot "d:/wamp/www" ServerName www.test.com
</VirtualHost>
<virtualhost *:80>
documentroot "D:/wamp/www/test1"
ServerName www.test1.com
</VirtualHost>
<virtualhost *:80>
documentroot "D:/wamp/www/test2"
ServerName www.test2.com
</VirtualHost>
4, testing:
Open the browser to enter Http://www.test.com, http://www.test1.com, http://www.test2.com to access different Web sites. Four description of virtual host configuration file Parameters
<virtualhost *:* >
ServerAdmin # Administrator's e-mail address
DocumentRoot # Virtual host root directory
ServerName # Virtual host name Port
ErrorLog # Virtual Host error log path
customlog # Virtual Host access log path
</VirtualHost>