[Recommended] configure multiple VM sites locally based on Apache

Source: Internet
Author: User

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.

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.