Apache configuration virtual Host and virtual directory

Source: Internet
Author: User

Apache configuration virtual Host and virtual directory

Learn about the relationship between the root directory and the virtual directory:

After installing Apache, opening the httpd.conf file will find that the DocumentRoot default setting should be the Htdocs folder in the Apache installation directory. Then your page can zoom in on this Htdocs folder test, example you put a 1.php, you can enter http://127.0.0.1/1.php to test. The path behind this documentroot is the root directory of Apache. Sometimes we do not want to put our own site here, for example I want to put in f:/myphp to run, then you can modify DocumentRoot to f:/myphp, and then put that 1.php into the f:/myphp folder, also use HTTP// 127.0.0.1/1.php can be accessed normally.

What is a virtual directory? As the name implies is only a virtual directory, and the real directory is a difference. Take a look at the use of real directory access, we created a folder in the previous f:/myphp Test, and then put 2.php inside, this time can be accessed through http://127.0.0.1/Test/2.php. However, there are a number of reasons why you might have a mapping between the folder you are creating and the access address you want to enter, rather than just typing the test folder name, so there's a lot of security issues, because then someone else will know the folder of your root directory. Specifically, you placed 2.php in the Test folder, but what if you want to access 2.php via http://127.0.0.1/cmj/2.php instead of through http://127.0.0.1/Test/2.php? This time we need a virtual directory, it is obvious that there is no CMJ this folder, but it can be accessed like a formal directory, you need a mapping relationship. How do you do it? Add in httpd.conf:

ALIAS/CMJ "f:/myphp/test/"

<directory "F:/myphp/test" >

Options Indexes FollowSymLinks

AllowOverride None

Order Allow,deny

Allow from all

</Directory>

Explain what the meaning is, the most important is the previous sentence alias/cmj "f:/myphp/test/", it means that I can access the f:/myphp/test/by adding/CMJ after the directory access. Behind the main is to set permissions issues, here no longer redundant.

Simply put, open httpd.conf at the end to add the following:

<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" for your site Directory: Restart apache2 after the configuration of your virtual host, you can later through the 127.0.0.2, and 127.0.0.3 into different sites.

The following is a detailed description of the analysis:

When we installed Apache, the general default Apache configuration is only one site, so it is inconvenient to switch. In fact, this problem is very good solution, that is, the native Apache configuration to become a virtual server. However, most of the online tutorial is to teach Apache how to configure a domain-based virtual host, and in the local debugging site, usually with the native IP (127.0.0.1 or localhost) directly access, no use of the domain name. So you have to configure Apache to be an IP address-based virtual host.

First of all, we all know that all 127 IP addresses should point to this machine, not just 127.0.0.1, you can try it.

This means that the machine has enough IP addresses for you to open a virtual host.

Nonsense, go into the formal configuration work, below is the configuration section of Apache Httpd.conf (httpd.conf is located in apache2.2\conf):

1, listen part, must specify the port directly, do not specify an IP address, the configuration should be written as:

Listen 80

2. Do not write "Namevirtualhost" like a domain-based virtual host.

3, Virtual host Configuration segment: In Httpd.conf last add

<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

</v Irtualhost>

4, then the corresponding configuration of the various directory properties, the following is a typical configuration of directory properties:

<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 restarting Apache2, your virtual host will be configured, and then you can enter different sites through 127.0.0.1 and 127.0.0.2,127.0.0.3.


Apache configuration virtual Host and virtual directory

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.