1. Modify the domain name access method:
Run: c: \ windows \ system32 \ drivers \ etc
Open:HostS file
Add Domain Name Pointing.
2. Modify httpd. conf.
Before the configuration takes effect, you must change it to the following directory:
<Directory/>
Options followsymlinks
AllowOverride none
### Order deny, allow
### Deny from all
Order allow, deny
Allow from all
Satisfy all
</Directory>
Otherwise, access is not permitted.
3. VM Configuration
(1) ip address-based Virtual Host Configuration
Listen 80
<VirtualHost172.20.30.40>
DocumentRoot/www/example1
Servername www.example1.com
</VirtualHost>
<VirtualHost172.20.30.50>
DocumentRoot/www/example2
Servername www.example2.org
</VirtualHost>
(2) IP-based and multi-port Virtual Host Configuration
Listen 172.20.30.40: 80
Listen 172.000030.40: 8080
Listen 172.20.30.50: 80
Listen 172.20.30.50: 8080
<VirtualHost172.20.30.40: 80>
DocumentRoot/www/example1-80
Servername www.example1.com
</VirtualHost>
<VirtualHost172.20.30.40: 8080>
DocumentRoot/www/example1-8080
Servername www.example1.com
</VirtualHost>
<VirtualHost172.20.30.50: 80>
DocumentRoot/www/example2-80
Servername www.example1.org
</VirtualHost>
<VirtualHost172.20.30.50: 8080>
DocumentRoot/www/example2-8080
Servername www.example2.org
</VirtualHost>
(3) domain name-based VM configuration on a server with a single IP Address:
# Ensure that Apache listens on port 80
Listen 80
# Listen for virtualHostRequests on all IP addresses
NamevirtualHost*: 80
<VirtualHost*: 80>
DocumentRoot/www/example1
Servername www.example1.com
Serveralias example1.com. * .example1.com
# Other directives here
</VirtualHost>
<VirtualHost*: 80>
DocumentRoot/www/example2
Servername www.example2.org
# Other directives here
</VirtualHost>
(4) configure a domain name-based VM on a server with multiple IP addresses:
Listen 80
# This is the "Main" server running on 172.20.30.40
Servername server.domain.com
DocumentRoot/www/mainserver
# This is the other address
NamevirtualHost172.20.30.50
<VirtualHost172.20.30.50>
DocumentRoot/www/example1
Servername www.example1.com
# Other directives here...
</VirtualHost>
Ixdba. netCommunityForum
<VirtualHost172.20.30.50>
DocumentRoot/www/example2
Servername www.example2.org
# Other directives here...
</VirtualHost>
(5) run different sites on different ports (configure a domain name-based virtual host on a multi-port server ):
Listen 80
Listen 8080.
NamevirtualHost172.20.30.40: 80
NamevirtualHost172.20.30.40: 8080
<VirtualHost172.20.30.40: 80>
Servername www.example1.com
DocumentRoot/www/domain-80
</VirtualHost>
<VirtualHost172.20.30.40: 8080>
Servername www.example1.com
DocumentRoot/www/domain-8080
</VirtualHost>
<VirtualHost172.20.30.40: 80>
Servername www.example2.org
DocumentRoot/www/otherdomain-80
</VirtualHost>
<VirtualHost172.20.30.40: 8080>
Servername www.example2.org
DocumentRoot/www/otherdomain-8080
</VirtualHost>
(6) configuration of domain name-based and IP-based Hybrid Virtual Hosts:
Listen 80
NamevirtualHost172.20.30.40
<VirtualHost172.20.30.40>
DocumentRoot/www/example1
Servername www.example1.com
</VirtualHost>
<VirtualHost172.20.30.40>
DocumentRoot/www/example2
Servername www.example2.org
</VirtualHost>
<VirtualHost172.20.30.40>
DocumentRoot/www/example3
Servername www.example3.net
</VirtualHost>
========================================================== ========================================
Simply put, open httpd. conf and add the following content at the end:
<VirtualHost127.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, the local IP address (127.0.0.1 or localHost. 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 "namevirtual" as the domain name-based Virtual HostHost".
3. VM configuration section: add
<VirtualHost127.0.0.2: 80>
DocumentRoot D:/appserv/www2
Servername 127.0.0.2: 80
</VirtualHost>
<VirtualHost127.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:
<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, deny
Allow from all
</Directory>
After you restart apache2, your VM is configured. Then, you can access different sites through 127.0.0.1, 127.0.0.2, and 127.0.0.3.