apache2.2 Virtual Host configuration, apache2.2 detailed _php tutorial

Source: Internet
Author: User

apache2.2 Virtual Host Configuration detailed, apache2.2 detailed


I. Modification of HTTPD.CONF

Open the Appserv installation directory, locate the httpd.conf file, and remove the # number in front of the following two lines, respectively.

#LoadModule Vhost_alias_module modules/mod_vhost_alias.so  

Remove # means enable Apache's virtual host feature.

#Include conf/extra/httpd-vhosts.conf

To get rid of this line, it means to import the virtual host configuration from the conf/extra/httpd-vhosts.conf file.

Ii. Modification of httpd-vhosts.conf

Open the file and see something like the following. The configuration of the virtual host is also configured with reference to the following content. This content is explained below

Namevirtualhost *:80    
 
  
   
        ServerAdmin webmaster@dummy-host.www.phpStudy.net      documentroot "C:/Program Files/apache2/docs/dummy-host.www.phpstudy.net "      ServerName dummy-host.www.phpstudy.net      Serveralias Www.dummy-host.www.phpStudy.net      errorlog "Logs/dummy-host.www.phpstudy.net-error.log"      customlog "logs/ Dummy-host.www.phpstudy.net-access.log "Common  
 
    

Namevirtualhost *:80

Note 1:namevirtualhost Specifies the IP address or domain name used by the virtual host, but preferably an IP address. When using a domain-based virtual host, Namevirtualhost is the necessary instruction. Namevirtualhost can define multiple. NOTE 2: All requests that conform to Namevirtualhost or label definitions are processed as virtual hosts, and the primary server is ignored. Namevirtualhost defines a request that is not defined by the label, the server cannot find the corresponding virtual host and will not be able to process it. So each namevirtualhost-defined parameter must have at least one match. Note 3: If you set Namevirtualhost or *:80, all requests for 80 ports will be handled by the virtual host, and the request will be directed to a virtual host based on the domain name. If there is a request from port 80, and the requested domain name is not configured as a virtual host, it will point to the first virtual host. This way, the primary server will not be able to receive any requests from port 80. To do this, you also configure a virtual host for the primary server.

ServerAdmin Admin Mailbox

DocumentRoot Site Directory (note: If the path in the site directory has spaces, enclose the path with double quotes)

ServerName the domain name to bind to (required)

Serveralias the alias of the virtual host to bind. (optional, if multiple domain names are separated by a space, if not, the line is removed)

Support *,? Two wildcard characters, such as *.abc.com, indicate that any one of the abc.com's two-level domain names is accessible.

Customlog user log file (optional, if not required, remove the line)

Errorlog error log (optional, if not required, remove the line)

IP address-based virtual host

 
  
   
      Documentroot/www/example1    ServerName www.example.com  
 
    

 
  
   
      Documentroot/www/example2    ServerName www.example.org  
 
    

Each virtual host can define multiple IPs, separated by a space

Hybrid of various virtual hosts

Listen  Listen bayi    namevirtualhost 172.20.30.40    
 
  
   
        documentroot/www/example1      ServerName www.example.com  
 
      
 
  
   
        documentroot/www/example2      ServerName www.example.org  
 
      namevirtualhost 172.20.30.40:81    
 
  
   
        documentroot/www/example3      ServerName www.example3.net  
 
      #  
 ip-based 
  
   
        documentroot/www/example4      ServerName www.example4.edu  
 
      
 
  
   
        documentroot/www/example5      ServerName Www.example5.gov  
 
    

Problems when a virtual host is mixed

One, the virtual host mix can be understood as follows: a line of namevirtualhost directives defined by all the virtual host group, the group and an IP-based virtual host peer. That is, the entire group defined by a row of Namevirtualhost as an IP-based virtual host. Second, the port specified by the virtual host must be listen defined. If the virtual host does not have a specified port, it is considered to be port 80. If namevirtualhost * is defined, it refers to all defined ports for all addresses. Third, more specific address definition is preferred. For example, if the Namevirtualhost directive defines *:80, and an IP-based virtual host is defined as 192.168.0.1:80, then if there is a request for 192.168.0.1:80, then the request will be prioritized 192.168.0.1 : 80 defines the virtual host. Therefore, in order to avoid confusion, do not define the intersection of each other or contain the range of addresses. 四、一个 virtual host, which can be both domain-based and IP-based. As the last virtual host in the previous example. Requests that conform to both definitions will be referred to the same virtual host. Sometimes it is necessary to differentiate the intranet from accessing the virtual host, because requests from the intranet may not be the same as requests from the extranet, but they need to point to the same virtual host.

Using the "_default_" virtual host

This virtual host can be understood as an IP-based virtual host

 
  
   
        Documentroot/www/default  
 
    

This virtual host will take over requests that do not match the IP and port of other virtual hosts. However, the primary server will not process any requests. Therefore, it is necessary to configure the master server as a virtual host.

A virtual host that the local machine agent runs on another machine

 
  
   
        Proxypreservehost on      proxypass/foo/no!      Proxypass/foo http://192.168.111.2      proxypassreverse/foo http://192.168.111.2      ServerName Hostname.example.com  
 
  

First, this is an IP-based virtual host that receives and processes requests for IP address 158.29.33.248. Second, Proxypass/foo http://192.168.111.2 will convert the request to Http://158.29.33.248/foo to a proxy request, which points to http://192.168.111.2. Three, proxypass/foo/no! The request for/foo/no is not proxied. This must be placed before the normal proxy instructions. Proxypreservehost on means transmitting the host information of the original request to the machine being proxied. Five, Proxypassreverse/foo http://192.168.111.2 can ensure that the request URL is redirected on other machines, the native processing can also be consistent. See the manual for the reverse proxy section specifically. Six, the domain-based virtual host is the same truth. Regardless of the type of virtual host, it only handles requests that are processed by it.

Configuration instance

Requirement 1:

This is an IP-based virtual host usage instance

A project data application, in order to prevent the domain name resolution problem caused by the inability to access the normal, so IP access to the interface. For example: http://61.122.3.6:8080/such a way. The configuration of the virtual host is as follows:

1, in httpd.conf Listen 80 add a line below, the content is: Listen 8080, that is, listening to 8080 port

2. Configure the Virtual host configuration

#NameVirtualHost 61.122.3.6:8080 This line can not be used. After testing, the IP address-based virtual host can not set the Namevirtualhost key.  
 
  
   
        ServerAdmin webmaster@dummy-host.www.phpStudy.net      documentroot "D:/web/openj"  
 
    

http://www.bkjia.com/PHPjc/1072328.html www.bkjia.com true http://www.bkjia.com/PHPjc/1072328.html techarticle apache2.2 Virtual Host configuration, apache2.2 detailed one, modify httpd.conf open Appserv installation directory, find httpd.conf files, respectively, remove the following two lines of text in front of the # number. #...

  • Related Article

    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.