Apache虚拟主机配置说明 打印 E-mail
  2007-12-15
一、使用 mod_vhost_alias

1、简单的动态虚拟主机  

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

# 这里的日志格式,可以在将来通过第一个参数域来分隔不同的虚拟主机的日志 
LogFormat "%V %h %l %u %t "%r" %s %b" vcommon  
CustomLog logs/access_log vcommon  

# 在返回请求的文件名的路径中包含进服务器名字: server name 
VirtualDocumentRoot /www/hosts/%0/docs 
VirtualScriptAlias /www/hosts/%0/cgi-bin  

2、更为有效的基于 IP 地址的虚拟主机 

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

# 在日志中包含 IP 地址,便于后续分发
LogFormat "%A %h %l %u %t "%r" %s %b" vcommon 
CustomLog logs/access_log vcommon 

# 在文件路径中包含 IP 地址  
VirtualDocumentRootIP /www/hosts/%0/docs 
VirtualScriptAliasIP /www/hosts/%0/cgi-bin  

二、使用 mod_rewrite 

1、使用 mod_rewrite 实现简单的动态虚拟主机 

# 从 Host: 头获取服务器名字
UseCanonicalName Off

# 可分割的日志  
LogFormat "%{Host}i %h %l %u %t "%r" %s %b" vcommon  
CustomLog logs/access_log vcommon
  
# ExecCGI is needed here because we can’t force 
# CGI execution in the way that ScriptAlias does
Options FollowSymLinks ExecCGI 
 

# 接下来是关键部分

RewriteEngine On 
# a ServerName derived from a Host: header may be any case at all RewriteMap lowercase int:tolower

## 首先处理普通文档: 

# 允许变名 /icons/ 起作用 - 其他变名类同 
RewriteCond %{REQUEST_URI} !^/icons/  

# 允许 CGIs 中 
RewriteCond %{REQUEST_URI} !^/cgi-bin/ 

# 开始“变戏法” 
RewriteRule ^/(.*)$ /www/hosts/${lowercase:%{SERVER_NAME}}/docs/$1 

## 现在处理 CGIs - 我们需要强制使用一个 MIME 类型  
RewriteCond %{REQUEST_URI} ^/cgi-bin/  
RewriteRule ^/(.*)$ /www/hosts/${lowercase:%{SERVER_NAME}}/cgi-bin/$1 [T=application/x-httpd-cgi] 

# 好了! 

2、使用独立的虚拟主机配置文件 vhost.map  

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:/www/conf/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

发表评论
网友评论
onestoptown
作者 访客 于 2008-11-20 12:44:28
shoes online buy shoes sandal shoes slippers shoes ecco shoes rockport shoes
steve madden shoes - puma shoes -  
nike shoes  
nike shoes replica  
replica nike shoes
air jordan shoes  
replica watches rolex  
replica watch - rolex watch - fake rolex watches
oyster rolex  
rolex watches
replica watches
replica rolex watches - rolex replica - watches online
oyster rolex watch - quartz watch fake - nike shoes - nike shoes replica - replica nike shoes
air jordan shoes - replica watches rolex - replica watch - rolex watch - fake rolex watches
oyster rolex - rolex watches - replica watches - replica rolex watches - rolex replica - watches online
oyster rolex watch - quartz watch fake -  
best replica watches 
rolex watches - replica watches - replica nike shoes - jordan shoes - watches online
oyster rolex watch - quartz shoes fake -  
nike shoeses
fd8ttr4
作者 访客 于 2008-11-21 14:00:29
fd8ttr4 
11lamam 
wow gold 
wow power leveling 
brogame 
brogame 
brogame 
wowmine.com 
wowmine.com 
人力资源管理师 
人力资源管理师 
人力资源管理师 
人力资源培训 
人力资源培训 
人力资源培训 
格力空调 
格力空调 
格力空调 
大金空调 
大金空调 
大金空调 
空调 
空调 
空调 
大金中央空调 
大金中央空调 
大金中央空调 
美的中央空调 
美的中央空调 
美的中央空调 
家用中央空调 
家用中央空调 
家用中央空调 
格力中央空调 
格力中央空调 
格力中央空调 
人力资源管理师 
人力资源管理师 
人力资源培训 
人力资源培训 
格力空调 
大金空调 
空调 
空调

发表评论
用户访客
标题
BBCode:Web AddressEmail AddressBold TextItalic TextUnderlined TextQuoteCodeOpen ListList ItemClose List
评论



最近更新 ( 2007-12-16 )
< 上一篇   下一篇 >