Dynamic configuration of large-capacity Virtual Hosts

Source: Internet
Author: User

Method 1: Simple Dynamic VM
Code:
This is the configuration method of the virtual host in the httpd. conf file. mod_vhost_alias is used here.

# Obtain the server name from host: Header server name
UseCanonicalName off

# Here, the log format can be used to separate logs of different virtual hosts using the first parameter field in the future
Logformat "% v % H % L % u % t/" % R/"% S % B" vcommon
Customlog logs/access_log vcommon

# Include the server name in the path of the returned request file name
Virtualdocumentroot/root directory of the VM space/% 0/htdocs
Virtualscriptalias/root directory of the VM space/% 0/cgi-bin
# Create/% 0/htdocs first, and put the file in htdocs for access
# % 0 indicates the name of the server name of the VM, for example, www.net.cn.

Change UseCanonicalName off to UseCanonicalName DNS to implement IP address-based virtual hosts. The server name to be inserted in the file path is parsed by the IP address of the VM.

Method 2: Multiple Dynamic Virtual Hosts
Code:
UseCanonicalName off

Logformat "% v % H % L % u % t/" % R/"% S % B" vcommon

<Directory/www/commercial>

Options followsymlinks
AllowOverride all

</Directory>

<Directory/www/homepages>

Options followsymlinks
AllowOverride none

</Directory>

<Virtualhost 111.22.33.44>

Servername www.commercial.isp.com

Customlog logs/access_log.commercial vcommon

Virtualdocumentroot/www/commercial/% 0/docs
Virtualscriptalias/www/commercial/% 0/cgi-bin

</Virtualhost>

<Virtualhost 111.22.33.45>

Servername www.homepages.isp.com

Customlog logs/access_log.homepages vcommon

Virtualdocumentroot/root directory of the VM space/% 0/htdocs
Virtualscriptalias/root directory of the VM space/% 0/cgi-bin

</Virtualhost>

Method 3: IP address-based VM
Code:

# Obtain the server name from IP address reverse resolution)
UseCanonicalName DNS

# Include IP addresses in logs to facilitate subsequent distribution
Logformat "% A % H % L % u % t/" % R/"% S % B" vcommon
Customlog logs/access_log vcommon

# Include IP address % 0 in the file path to indicate IP Address
Virtualdocumentrootip/www/hosts/% 0/docs
Virtualscriptaliasip/www/hosts/% 0/cgi-bin

Method 4: mod_rewrite VM System
Code:

Rewriteengine on

Rewritemap lowercase INT: tolower

# Check whether the hostname is correct before rewriterule can take effect
Rewritecond $ {lowercase: % {SERVER_NAME} ^ www/. [A-z-] +/. ISP/. com $

# Clean the VM name to the beginning of the URI
# [C] indicates that the result of this rewrite will be used in the next rewrite rule
Rewriterule ^ (. +) $ {lowercase: % {SERVER_NAME }}$ 1 [c]

# Create the actual file name
Rewriterule ^ www/. ([A-z-] +)/. ISP/. com/(. *)/home/$1/$2

Highlights
Method 5: Use an independent VM configuration file
When you modify vhost. map, you do not need to restart Apache.
Code:

This layout utilizes the advanced features of mod_rewrite to convert data in an independent VM configuration file. This can be more flexible, but requires more complex settings.

The vhost. map file contains content similar to the following:

Www.customer-1.com/www/Mers MERs/1
Www.customer-2.com/www/Mers MERs/2
#......
Www.customer-N.com/www.mers MERs/n

HTTP. conf includes:

Rewriteengine on

Rewritemap lowercase INT: tolower

# Defining image files
Rewritemap vhost TXT:/vhost. Map path/vhost. Map

# Process name change as in the preceding example
Rewritecond % {request_uri }! ^/Icons/
Rewritecond % {request_uri }! ^/Cgi-bin/
Rewritecond $ {lowercase: % {SERVER_NAME} ^ (. +) $
# File-based re ing
Rewritecond $ {vhost: % 1} ^ (/. *) $
Rewriterule ^/(. *) $ % 1/docs/$1

Rewritecond % {request_uri} ^/cgi-bin/
Rewritecond $ {lowercase: % {SERVER_NAME} ^ (. +) $
Rewritecond $ {vhost: % 1} ^ (/. *) $
Rewriterule ^/(. *) $ % 1/cgi-bin/$1

<Virtualhost *: 81>
# Include the server name in the filenames used to satisfy requests
Virtualdocumentroot D:/usr/www/html/% 2 +/web/% 1
Virtualscriptalias D:/usr/www/html/% 2 +/web/cgi-bin
<Directory "D:/usr/www/html/nicenic.net/web/">
Options + Indexes
</Directory>
# Jkmount/*. jsp ajp13
# Jkmount/*. Do ajp13
# Jkmount/servlet/* ajp13
# Jkmount/manager/* ajp13
# Jkmount/WEB-INF/* ajp13
</Virtualhost>

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.