There are many ways to configure virtual hosts in Apache, and there are also many types, mainly divided into two categories: Name-based virtual hosts (each IP Address has multiple sites) IP-based virtual hosts (each IP Address has one site) name-based Virtual Host: the configuration file conf/httpd of Apache in windows at www.2cto.com. to load the VM configuration file/extra/httpd-vhosts.conf in conf, find Include "conf/extra/httpd-vhosts.conf" uncomment. Now, in the httpd-vhosts.conf, start configuring our VM. Suppose we have two different sites on the same apache server. Both www.a.com and www. B .com point to the same ip address :***. ***. * ** we want www.a.com to access website a. The directory is/htdocs/a www. B .com to access website B. The directory is/htdocs/bhttpd-vhosts.conf code is as follows: 01 NameVirtualHost *: 80 // specify all ip Ports to access 02 <VirtualHost *: 80> 03 ServerName www. a. com04 DocumentRoot "X:/htdocs/a" 05 www.2cto.com <Directory "X:/htdocs/a"> // if not added, this will show AccessForbidden06 Options Indexes FollowSymLinks07 AllowOverride All // The default value is AllowOverride None. Here it is changed to All to allow access. htaccess08 Order allow, deny09 Allow from all10 </Directory> 11 </VirtualHost> 12 13 <VirtualHost *: 80> 14 ServerName www. b. com15 DocumentRoot "X:/htdocs/B" 16 <Directory "X:/htdocs/B"> 17 Options Indexes FollowSymLinks18 AllowOverride None19 www.2cto.com Order allow, deny20 Allow from all21 </Directory> 22 </VirtualHost>
So far, your configuration should have ended. But don't rush to restart the server. Use the httpd-S command to see how apache resolves the issue. If you have modified the httpd. conf file, use the httpd-t command. If you see 1 default server www.a.com (F:/apache/conf/extra/httpd-vhosts.conf: 46) 2 3 port 80 namevhost www.a.com (F:/apache/conf/extra/httpd-vhosts.conf: 464 5 port 80 namevhost www. B .com (F:/apache/conf/extra/httpd-vhosts.conf: 576 www.2cto.com Syntax OK so, go to restart the server, visit www.a.com. He will parse the website under directory. If you don't have a Domain Name and want to test the effect locally, it's easy to add 1127.0.0.1 www. a. com2127.0.0.1 www. B .com to your hosts file. You can try to change * to Ip address based on ip address.