apache2.2 Virtual Host configuration (RPM)

Source: Internet
Author: User

Turn from: http://blog.csdn.net/zm2714/article/details/8351342 First, change httpd.conf

Open the Appserv installation folder, locate the httpd.conf file, and then remove the # number in front of the following two lines of text, 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.

Second, change httpd-vhosts.conf

Open the file and see something like the following. The configuration of the virtual host is also included in the following configuration. This content is explained below

Namevirtualhost *:80<virtualhost *:80>    ServerAdmin [email protected]    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</virtualhost>
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 the definition of namevirtualhost or <VirtualHost> tags are processed as virtual hosts, and the primary server is ignored. Namevirtualhost defines a request that is not defined by the <VirtualHost> tag, and the server cannot find the corresponding virtual host and will not be able to process it. So each of the namevirtualhost defined parameters must have at least one <VirtualHost> match.
Note 3: Assuming that the settings namevirtualhost or <VirtualHost> for *:80, all requests for 80port will be processed by the virtual host, the request according to the domain name point to a virtual host. Suppose there is a request from 80port, 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 80port. To do this, you also configure a virtual host for the primary server.

ServerAdmin Admin Mailbox

DocumentRoot site folder (Note: If the path in the site folder has spaces, add a double argument to both ends of the path)

ServerName the domain name to bind to (required)

Serveralias the alias of the virtual host to bind. (optional, assuming multiple domain names, separated by a space, assuming no, then remove the line)

Support *,? Two wildcards, such as *.abc.com, indicate that you can access a abc.com two-level domain.

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

<virtualhost>  documentroot/www/example1  ServerName www.example.com</VirtualHost >
<virtualhost>  documentroot/www/example2  ServerName www.example.org< /virtualhost>
Each virtual host can define multiple IPs, separated by a space

Hybrid of various virtual hosts

Listen 80Listen 81NameVirtualHost<virtualhost>    documentroot/www/example1    ServerName www.example.com</VirtualHost><VirtualHost>    documentroot/www/example2    ServerName www.example.org</VirtualHost>NameVirtualHost<virtualhost >    documentroot/www/example3    ServerName www.example3.net</VirtualHost># ip-based<virtualhost>    documentroot/www/example4    ServerName www.example4.edu</virtualhost>< VirtualHost>    documentroot/www/example5    ServerName www.example5.gov< /virtualhost>

Problems when a virtual host is mixed

One, the virtual host mix can understand this: a line of namevirtualhost directives defined by a group of all virtual hosts, 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. Assuming that the virtual host does not specify port, it is 80port. Assuming that namevirtualhost * is defined, it means all defined ports for all addresses.
Third, more detailed address definition is preferred. For example, if the Namevirtualhost directive defines *:80, and an IP-based virtual host is defined as, then if there is a request for, then the request will be prioritized : 80 defines the virtual host. Therefore, in order to avoid confusion, do not define the intersection of each other or include the address range.
四、一个 virtual hosts can be domain-based and IP-based at the same time. 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 make a difference between the intranet and the virtual host, because requests from the network 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

<virtualhost _default_:*>    documentroot/www/default</virtualhost>
This virtual host will take over requests that do not match the IP and port of other virtual hosts. Only in this way, the primary server will not process any requests whatsoever. Therefore, it is necessary to configure the primary server as a virtual host.

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

<virtualhost>    proxypreservehost on    proxypass/foo/no!    Proxypass/foo    proxypassreverse/foo    ServerName Hostname.example.com</virtualhost>
First, this is an IP-based virtual host that receives and processes requests for IP address
Second, Proxypass/foo will convert the request to Http:// to a proxy request, which points to
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 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 in detail.
Six, the domain-based virtual host is the same reason. No matter what type of virtual host it is, it simply 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 the use of IP access to the interface. Analogy: way. The configuration of the virtual host is as follows:

1, in httpd.conf Listen 80 Add the following line, the content is: Listen 8080, that is, monitoring 8080port

2. Configure the Virtual host configuration

#NameVirtualHost This line is not required. After testing, the virtual host based on IP address can not set the Namevirtualhost item. <virtualhost>    ServerAdmin [email protected]    documentroot "D:/web/openj" </ Virtualhost>

apache2.2 Virtual Host configuration (RPM)

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.