Simply put, open httpd. conf and add the following content at the end:
Code
< Virtualhost 127.0 . 0.2 : 80 >
DocumentRoot d :/ Appserv / Www2
Servername 127.0 . 0.2 : 80
</ Virtualhost >
<Directory"D:/appserv/www2">
Options indexes followsymlinks Multiviews
AllowOverride all
Order allow,Deny
Allow from all
</Directory>
"D:/appserv/www2" stores your site directory: After you restart apache2, your VM is configured. Then, you can access different sites through 127.0.0.2 and 127.0.0.3.
The detailed analysis is as follows:
When we install Apache, the default Apache configuration usually has only one website, which is inconvenient to switch. In fact, this problem is well solved by configuring Apache on the local machine as a virtual server. However, most tutorials on the Internet teach you how to configure a domain name-based virtual host using Apache. When debugging a website on the local machine, it is generally accessed directly using a local IP address (127.0.0.1 or localhost, no domain name is used. Therefore, you must configure Apache as an IP address-based virtual host.
First, we all know that all IP addresses starting with 127 should point to the local machine, not only 127.0.0.1. You can try this.
In this way, the host has enough IP addresses for you to open a VM.
To put it bluntly, go to the official configuration work. The configuration section in httpd. conf of Apache is as follows (httpd. conf is in apache2.2 \ conf ):
1. In the listen section, the port must be specified directly without an IP address. The configuration should be written as follows:
Listen 80
2. You do not need to write "namevirtualhost" like a domain name-based virtual host ".
3. VM configuration section: add
Code
< Virtualhost 127.0 . 0.2 : 80 >
DocumentRoot D: / Appserv / Www2
Servername 127.0 . 0.2 : 80
</ Virtualhost >
< Virtualhost 127.0 . 0.3 : 80 >
DocumentRoot D: / Appserv / Www3
Servername 127.0 . 0.3 : 80
</ Virtualhost >
4. Configure the directory attributes accordingly. The following is a typical configuration of the Directory attributes:
Code
< Directory " D:/appserv/www2 " >
Options indexes followsymlinks Multiviews
AllowOverride all
Order allow, deny
Allow from all
</ Directory >
directory " D:/appserv/www3 " >
options indexes followsymlinks Multiviews
AllowOverride all
order allow, den Y
allow from all
directory >
after apache2 is restarted, after you have configured your Vm, you can use 127.0.0.1, 127.0.0.2, and 127.0.0.3 to access different sites.