Apache configures virtual hosts in many ways, many kinds, mainly divided into two types of: name-based virtual host (each IP multiple sites) IP-based virtual host (one site per IP) name-based virtual host: www.2cto.com Under Windows apache configuration file conf/httpd.conf load the virtual host profile /extra/httpd-vhosts.conf find the Include "conf/extra/ Httpd-vhosts.conf "to cancel the comment. Now, to httpd-vhosts.conf, start configuring our virtual hosts. Assuming we have two different sites on the same Apache server, www.a.com and www.b.com all point to the same IP:* **.***.*** we want www.a.com to visit site A, directory/htdocs/a & nbsp www.b.com visit site B, directory/htdocs/bhttpd-vhosts.conf code as follows: 01NameVirtualHost *:80 &nbs p;//Specify all IP ports to access 02<virtualhost *:80>03 ServerName www.a.com04 DocumentRoot "x:/htdocs/a" www.2cto.com <directory "x:/htdocs/a" >//If not added, this will appear AccessForbidden06 Options Indexes Followsym links07 allowoverride all//default is allowoverride None modified hereFor all purposes you can access .htaccess08 Order allow,deny09 &N Bsp 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 &NBSP ; Options Indexes followsymlinks18 allowoverride None19 www.2cto.com Order allow,deny20 & nbsp allow from all21 </Directory>22</VirtualHost>
At this point, your configuration should be over. But don't worry about starting the server first, use the httpd-s command to see how Apache is parsed. If you modified the httpd.conf file, use the HTTPD-T command. If you see 1default server www.a.com (f:/apache/conf/extra/httpd-vhosts.conf:46) 2 3 port Namevhost www.a.com (f:/apache/ conf/extra/httpd-vhosts.conf:464 5 Port Namevhost www.b.com (f:/apache/conf/extra/httpd-vhosts.conf:576 Www.2cto.com Syntax OK then, to restart the server, visit Www.a.com Bar. He will resolve the site under the A directory. If you don't have a domain name and just 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. IP-based people can try to change the * to IP look.
[Linux] Apache Configure virtual Host