Apache Virtual Host Configuration: Level two directory access jumps to other root folders _linux

Source: Internet
Author: User

Access to http://www.abc.com/course/, the actual access is: D:/www/moodle/index. Php

<virtualhost *:80> 
  ServerAdmin webmaster@abc.com 
  documentroot "D:/WWW/ABC" 
  ServerName www.abc.com 
  # #ServerAlias  
  alias/course "D:/www/moodle" 
  <directory "D:/www/moodle" > 
    options FollowSymLinks 
    allowoverride None order  
    Deny,allow allow to all 
  </Directory> 

Take a look at the relationship between the root directory and the virtual directory:
When you open the httpd.conf file after you install Apache, you 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 inside. PHP, you can enter http://127.0.0.1/1.php for testing. The path behind this documentroot is the Apache root directory. Sometimes we don't want to put our website here, for example I want to put in f:/myphp to run, then can modify documentroot for f:/myphp, then put that 1.php into f:/myphp folder, same 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 different. First take a look at the use of real directory access, we have just set up a folder in the F:/myphp Test, and then put 2.php inside, this time can be accessed through the http://127.0.0.1/Test/2.php. But there are times when you might create a mapping relationship between a folder and the access address you want to enter, instead of typing the test folder name directly, and there are a number of reasons why there is a security issue, because then someone else will know your root directory folder. Specifically, you put 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 http://127.0.0.1/Test/2.php? This time we need a virtual directory, obviously not CMJ this folder, but also to access the same as a formal directory to access, 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>
To explain what it means, the most important is the previous sentence alias/cmj "f:/myphp/test/", which means that I can access things in f:/myphp/test/by adding/CMJ after accessing the IP in a more directory. The main behind is to set permissions issues, there is no longer redundant.

To put it simply, open httpd.conf at the end by adding 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 storage directory: Restart apache2 After, your virtual host is configured, then you can 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 to solve, that is, the native Apache configuration into a virtual server. However, most of the online tutorials are taught in Apache how to configure a domain-based virtual host, and in the local debugging site, the general is the use of native IP (127.0.0.1 or localhost) direct access, no use of domain names. So you have to configure Apache as a virtual host based on IP addresses.
First of all, we all know that all IP addresses that start with 127 should point to this machine, not just 127.0.0.1, which you can try.
This means that the machine has enough IP addresses for you to open the virtual host.
Needless to say, enter the formal configuration work, the following is the Apache httpd.conf related configuration section (httpd.conf located in apache2.2\conf):
1, the listen part, must specify the port directly, does not specify the IP address, the configuration should write as:
Listen 80
2. Do not write "Namevirtualhost" like a domain based virtual host.
3, the virtual host Configuration segment: At the end of Httpd.conf plus

<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
</v Irtualhost>

4, and 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 to all
</ Directory>

After restarting the apache2, your virtual host is configured, then you can enter the different sites through 127.0.0.1 and 127.0.0.2,127.0.0.3.

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.