several frequently used directives for apache server

本文详细介绍了Apache服务器中虚拟主机的概念及其配置方法。通过使用<VirtualHost>指令可以实现在同一台物理服务器上运行多个不同的网站。文章还特别解释了基于名称的虚拟主机配置示例,并强调了如何确保现有网站正常运行的同时添加新的虚拟主机。

摘要生成于 C知道 ,由 DeepSeek-R1 满血版支持, 前往体验 >

1.<vituralhost><vituralhost/>, this directive encloses/contains a group of directives and only apply to a paticular vitural host.
Syntax: <VirtualHost addr[:port] [addr[:port]] ...> ... </VirtualHost>
Available values for addr can be:
(1)IP address for virtual host
(2)full quailfied domain name for IP address(deprecated)
(3)*,used only in combination with NameVirtualHost * to match all IP address
(4)_default_,catch unmatched address
Annotation: what is virtual host? Virtual host is a term, 
it is used to describe the practice of
running more than one web site on a single machine.
Virtual can be based on ip which means each web site has its own address,
or domain name which means there have multiple names for each ip.
A typical example for name-based virtual host in HTTP server can be configured like this:
current IP has already been used to match www.yourdomain.itb,
but still can be used to match another virture machine:www.otherdomain.itb.
NameVirtualHost *:80  ----NameVirtualHost用来指定那个IP地址来接受请求,这里使用*匹配服务器上所有的地址
<VirtualHost *:80>
ServerName www.yourdomain.itb
ServerAlias yourdomain.itb *.yourdomain.itb
DocumentRoot /www/domain
</VirtualHost>
<VirtualHost *:80>
ServerName www.otherdomain.itb
DocumentRoot /www/otherdomain
</VirtualHost>
注意:如果向一个已经存在的web server添加虚拟机,需要一个为已经存在的创建<virtualhost>脚本,
这个虚拟机中所包含的ServerName和DocumentRoot要和全局的ServerName和DocumentRoot保持一致。
同时,把它放在配置文件中虚拟机列表的最前面,这样它就是缺省的虚拟机.
--待续
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值