search
HomeDatabaseMysql Tutorial大容量虚拟主机的动态配置

大容量虚拟主机的动态配置

Jun 07, 2016 pm 03:10 PM
HostdynamicmethodSimplevirtualvirtual hostConfiguration

方法一:简单的 动态 虚拟 主机 代码: 这是 httpd.conf 文件中,完成 虚拟 主机 的 配置 方法,这里采用了 mod_vhost_alias 。 # 从 Host: 头中取得服务器名字 Server Name UseCanonicalName Off # 这里的日志格式,可以在将来通过第一个参数域来分隔不同的 虚

方法一:简单的动态虚拟主机

代码:

这是 httpd.conf 文件中,完成虚拟主机配置方法,这里采用了 mod_vhost_alias 。

# 从 Host: 头中取得服务器名字 Server Name

UseCanonicalName Off

# 这里的日志格式,可以在将来通过第一个参数域来分隔不同的虚拟主机的日志

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

CustomLog logs/access_log vcommon

# 在返回请求的文件名的路径中包含进服务器名字: server name

VirtualDocumentRoot /虚拟主机空间根目录/%0/htdocs

VirtualScriptAlias /虚拟主机空间根目录/%0/cgi-bin

#需要首先建立 /%0/htdocs ,然后把文件放在htdocs才可以访问

#%0表示虚拟主机的Server Name的这个名字,例如www.net.cn

将 UseCanonicalName Off 的配置改为 UseCanonicalName DNS 即可实现基于 IP 地址的虚拟主机。而在文件路径中所要插入的服务器名字(server name) 则通过虚拟主机的 IP 地址解析而得。

方法二:多个的动态虚拟主机

代码:

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 /虚拟主机空间根目录/%0/htdocs

VirtualScriptAlias /虚拟主机空间根目录/%0/cgi-bin



方法三:基于 IP 地址的虚拟主机

代码:

# 从 IP 地址反解析得到服务器名字(server name)

UseCanonicalName DNS

# 在日志中包含 IP 地址,便于后续分发

LogFormat "%A %h %l %u %t "%r" %s %b" vcommon

CustomLog logs/access_log vcommon

# 在文件路径中包含 IP 地址 %0表示IP

VirtualDocumentRootIP /www/hosts/%0/docs

VirtualScriptAliasIP /www/hosts/%0/cgi-bin



方法四:使用 mod_rewrite 的虚拟主机系统

代码:

RewriteEngine on

RewriteMap lowercase int:tolower

# 检查 hostname 正确与否,之后才能使 RewriteRule 起作用

RewriteCond ${lowercase:%{SERVER_NAME}} ^www\.[a-z-]+\.isp\.com$

# 将虚拟主机名字廉洁到 URI 的开头

# [C] 表明本次重写的结果将在下一个 rewrite 规则中使用

RewriteRule ^(.+) ${lowercase:%{SERVER_NAME}}$1 [C]

# 现在创建实际的文件名

RewriteRule ^www\.([a-z-]+)\.isp\.com/(.*) /home/$1/$2



重头戏

方法五:使用独立的虚拟主机配置文件

当你修改vhost.map的时候,不需要重新启动Apache

代码:

这样的布局利用了 mod_rewrite 的高级特性, 在独立的虚拟主机配置文件中转换。如此可以更为灵活,但需要较为复杂的设置。

vhost.map 文件包含了类似下面的内容:

www.customer-1.com /www/customers/1

www.customer-2.com /www/customers/2

#......

www.customer-N.com /www/customers/N

http.conf 包含了:

RewriteEngine on

RewriteMap lowercase int:tolower

# 定义映像文件

RewriteMap vhost txt:/VHOST.map的路径/vhost.map

# 和上面的例子一样,处理变名

RewriteCond %{REQUEST_URI} !^/icons/

RewriteCond %{REQUEST_URI} !^/cgi-bin/

RewriteCond ${lowercase:%{SERVER_NAME}} ^(.+)$

# 这里做基于文件的重新映射

RewriteCond ${vhost:%1} ^(/.*)$

RewriteRule ^/(.*)$ %1/docs/$1

RewriteCond %{REQUEST_URI} ^/cgi-bin/

RewriteCond ${lowercase:%{SERVER_NAME}} ^(.+)$

RewriteCond ${vhost:%1} ^(/.*)$

RewriteRule ^/(.*)$ %1/cgi-bin/$1



引用:

以上内容来自Apache2的"动态配置大型虚拟主机",在这里列出来,是为了方便某些不想看文档的人参考一下子。

如果你去http://w.yi.org,使用关键字 虚拟主机 搜索一下子,相信会有更多的资料
Statement
The content of this article is voluntarily contributed by netizens, and the copyright belongs to the original author. This site does not assume corresponding legal responsibility. If you find any content suspected of plagiarism or infringement, please contact admin@php.cn
MySQL BLOB : are there any limits?MySQL BLOB : are there any limits?May 08, 2025 am 12:22 AM

MySQLBLOBshavelimits:TINYBLOB(255bytes),BLOB(65,535bytes),MEDIUMBLOB(16,777,215bytes),andLONGBLOB(4,294,967,295bytes).TouseBLOBseffectively:1)ConsiderperformanceimpactsandstorelargeBLOBsexternally;2)Managebackupsandreplicationcarefully;3)Usepathsinst

MySQL : What are the best tools to automate users creation?MySQL : What are the best tools to automate users creation?May 08, 2025 am 12:22 AM

The best tools and technologies for automating the creation of users in MySQL include: 1. MySQLWorkbench, suitable for small to medium-sized environments, easy to use but high resource consumption; 2. Ansible, suitable for multi-server environments, simple but steep learning curve; 3. Custom Python scripts, flexible but need to ensure script security; 4. Puppet and Chef, suitable for large-scale environments, complex but scalable. Scale, learning curve and integration needs should be considered when choosing.

MySQL: Can I search inside a blob?MySQL: Can I search inside a blob?May 08, 2025 am 12:20 AM

Yes,youcansearchinsideaBLOBinMySQLusingspecifictechniques.1)ConverttheBLOBtoaUTF-8stringwithCONVERTfunctionandsearchusingLIKE.2)ForcompressedBLOBs,useUNCOMPRESSbeforeconversion.3)Considerperformanceimpactsanddataencoding.4)Forcomplexdata,externalproc

MySQL String Data Types: A Comprehensive GuideMySQL String Data Types: A Comprehensive GuideMay 08, 2025 am 12:14 AM

MySQLoffersvariousstringdatatypes:1)CHARforfixed-lengthstrings,idealforconsistentlengthdatalikecountrycodes;2)VARCHARforvariable-lengthstrings,suitableforfieldslikenames;3)TEXTtypesforlargertext,goodforblogpostsbutcanimpactperformance;4)BINARYandVARB

Mastering MySQL BLOBs: A Step-by-Step TutorialMastering MySQL BLOBs: A Step-by-Step TutorialMay 08, 2025 am 12:01 AM

TomasterMySQLBLOBs,followthesesteps:1)ChoosetheappropriateBLOBtype(TINYBLOB,BLOB,MEDIUMBLOB,LONGBLOB)basedondatasize.2)InsertdatausingLOAD_FILEforefficiency.3)Storefilereferencesinsteadoffilestoimproveperformance.4)UseDUMPFILEtoretrieveandsaveBLOBsco

BLOB Data Type in MySQL: A Detailed Overview for DevelopersBLOB Data Type in MySQL: A Detailed Overview for DevelopersMay 07, 2025 pm 05:41 PM

BlobdatatypesinmysqlareusedforvoringLargebinarydatalikeImagesoraudio.1) Useblobtypes (tinyblobtolongblob) Basedondatasizeneeds. 2) Storeblobsin Perplate Petooptimize Performance.3) ConsidersxterNal Storage Forel Blob Romana DatabasesizerIndimprovebackupupe

How to Add Users to MySQL from the Command LineHow to Add Users to MySQL from the Command LineMay 07, 2025 pm 05:01 PM

ToadduserstoMySQLfromthecommandline,loginasroot,thenuseCREATEUSER'username'@'host'IDENTIFIEDBY'password';tocreateanewuser.GrantpermissionswithGRANTALLPRIVILEGESONdatabase.*TO'username'@'host';anduseFLUSHPRIVILEGES;toapplychanges.Alwaysusestrongpasswo

What Are the Different String Data Types in MySQL? A Detailed OverviewWhat Are the Different String Data Types in MySQL? A Detailed OverviewMay 07, 2025 pm 03:33 PM

MySQLofferseightstringdatatypes:CHAR,VARCHAR,BINARY,VARBINARY,BLOB,TEXT,ENUM,andSET.1)CHARisfixed-length,idealforconsistentdatalikecountrycodes.2)VARCHARisvariable-length,efficientforvaryingdatalikenames.3)BINARYandVARBINARYstorebinarydata,similartoC

See all articles

Hot AI Tools

Undresser.AI Undress

Undresser.AI Undress

AI-powered app for creating realistic nude photos

AI Clothes Remover

AI Clothes Remover

Online AI tool for removing clothes from photos.

Undress AI Tool

Undress AI Tool

Undress images for free

Clothoff.io

Clothoff.io

AI clothes remover

Video Face Swap

Video Face Swap

Swap faces in any video effortlessly with our completely free AI face swap tool!

Hot Tools

Dreamweaver Mac version

Dreamweaver Mac version

Visual web development tools

WebStorm Mac version

WebStorm Mac version

Useful JavaScript development tools

Dreamweaver CS6

Dreamweaver CS6

Visual web development tools

SublimeText3 English version

SublimeText3 English version

Recommended: Win version, supports code prompts!

MinGW - Minimalist GNU for Windows

MinGW - Minimalist GNU for Windows

This project is in the process of being migrated to osdn.net/projects/mingw, you can continue to follow us there. MinGW: A native Windows port of the GNU Compiler Collection (GCC), freely distributable import libraries and header files for building native Windows applications; includes extensions to the MSVC runtime to support C99 functionality. All MinGW software can run on 64-bit Windows platforms.