您好,欢迎来到思海网络,我们将竭诚为您提供优质的服务! 诚征网络推广 | 网站备案 | 帮助中心 | 软件下载 | 购买流程 | 付款方式 | 联系我们 [ 会员登录/注册 ]
促销推广
客服中心
业务咨询
有事点击这里…  531199185
有事点击这里…  61352289
点击这里给我发消息  81721488
有事点击这里…  376585780
有事点击这里…  872642803
有事点击这里…  459248018
有事点击这里…  61352288
有事点击这里…  380791050
技术支持
有事点击这里…  714236853
有事点击这里…  719304487
有事点击这里…  1208894568
有事点击这里…  61352289
在线客服
有事点击这里…  531199185
有事点击这里…  61352288
有事点击这里…  983054746
有事点击这里…  893984210
当前位置:首页 >> 技术文章 >> 文章浏览
技术文章

Apache的虚拟主机配置

添加时间:2010-11-21  添加: admin 

1.2 虚拟主机配置

首先用“记事本”程序打开“httpd.conf”配置文件。此文件存放在Apache服务器安装路径下的“conf”文件夹内。

一、使用 mod_vhost_alias

1.简单的动态虚拟主机

(1)从 Host: 头中取得服务器名字 Server Name

UseCanonicalName Off

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

LogFormat "%V %h %l %u %t "%r" %s %b" vcommon
CustomLog logs/access_log vcommon

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

VirtualDocumentRoot /www/hosts/%0/docs
VirtualScriptAlias /www/hosts/%0/cgi-bin

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

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

UseCanonicalName DNS

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

LogFormat "%A %h %l %u %t "%r" %s %b" vcommon
CustomLog logs/access_log vcommon

(3)在文件路径中包含 IP 地址

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

二、使用 mod_rewrite

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

(1)从 Host: 头获取服务器名字

UseCanonicalName Off

(2)可分割的日志

LogFormat "%i %h %l %u %t "%r" %s %b" vcommon
CustomLog logs/access_log vcommon
<Directory /www/hosts>
ExecCGI is needed here because we can't force
CGI execution in the way that ScriptAlias does
Options FollowSymLinks ExecCGI
</Directory>

(3)接下来是关键部分

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

首先处理普通文档:

允许变名 /icons/ 起作用 - 其他变名类同
RewriteCond % !^/icons/
允许 CGIs
RewriteCond % !^/cgi-bin/
开始“变戏法”
RewriteRule ^/(.*)$ /www/hosts/$}/docs/

现在处理 CGIs - 我们需要强制使用一个 MIME 类型

RewriteCond % ^/cgi-bin/
RewriteRule ^/(.*)$ /www/hosts/$}/cgi-bin/ [T=application/x-httpd-  cgi]


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

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

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

(2)http.conf 包含了:

RewriteEngine on
RewriteMap lowercase int:tolower

(3)定义映像文件

RewriteMap vhost txt:/www/conf/vhost.map

(4)和上面的例子一样,处理变名

RewriteCond % !^/icons/
RewriteCond % !^/cgi-bin/
RewriteCond $} ^(.+)$

(5)这里做基于文件的重新映射

RewriteCond $ ^(/.*)$
RewriteRule ^/(.*)$ %1/docs/
RewriteCond % ^/cgi-bin/
RewriteCond $} ^(.+)$
RewriteCond $ ^(/.*)$
RewriteRule ^/(.*)$ %1/cgi-bin/
分享到:

顶部 】 【 关闭
版权所有:佛山思海电脑网络有限公司 ©1998-2024 All Rights Reserved.
联系电话:(0757)22630313、22633833
中华人民共和国增值电信业务经营许可证: 粤B1.B2-20030321 备案号:粤B2-20030321-1
网站公安备案编号:44060602000007 交互式栏目专项备案编号:200303DD003  
察察 工商 网安 举报有奖  警警  手机打开网站