Dynamic configuration of large-capacity Virtual Hosts

Source: Internet
Author: User
Method 1: Simple Dynamic Virtual Host 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 ServerNameUseCanonicalNameOff from the Host: Header # The log format here can be separated by the first parameter field in the future

Method 1: Simple Dynamic Virtual Host 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 "Server Name UseCanonicalName Off" from the Host: Header # The log format here can be separated by the first parameter field in the future

Method 1: simple Dynamic Virtual Host

Code:

This is in the httpd. conf file. Virtual HostOf ConfigurationMod_vhost_alias is used here.

# Obtain the Server Name from Host: Header Server Name

UseCanonicalName Off

# The log format here can be separated by the first parameter field in the future Virtual HostLogs

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/ Virtual HostSpace root directory/% 0/htdocs

VirtualScriptAlias/ Virtual HostSpace root directory/% 0/cgi-bin

# Create/% 0/htdocs first, and put the file in htdocs for access

# % 0 Virtual HostFor example, www.net.cn.

Disable UseCanonicalName ConfigurationChange to UseCanonicalName DNS to implement IP address-based Virtual Host. The server name to be inserted in the file path is Virtual Host.

Method 2: Multiple Dynamic Virtual Host

Code:

UseCanonicalName Off

LogFormat "% V % h % l % u % t" % r "% s % B" vcommon



Options FollowSymLinks

AllowOverride All





Options FollowSymLinks

AllowOverride None





ServerName www.commercial.isp.com

CustomLog logs/access_log.commercial vcommon

VirtualDocumentRoot/www/commercial/% 0/docs

VirtualScriptAlias/www/commercial/% 0/cgi-bin





ServerName www.homepages.isp.com

CustomLog logs/access_log.homepages vcommon

VirtualDocumentRoot/ Virtual HostSpace root directory/% 0/htdocs

VirtualScriptAlias/ Virtual HostSpace root directory/% 0/cgi-bin



Method 3: IP address-based Virtual Host

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: Use mod_rewrite Virtual HostSystem

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 $

# Set Virtual HostThe name must start with 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 Virtual Host ConfigurationFile

When you modify vhost. map, you do not need to restart Apache.

Code:

This layout utilizes the advanced features of mod_rewrite Virtual Host ConfigurationFile conversion. 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



Reference:

The above content is from Apache2" Dynamic ConfigurationLarge Virtual Host", Which is listed here for reference by some people who do not want to read the document.

If you go to http://w.yi.org, use keywords Virtual HostSearch all at once, I believe there will be more information

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.