Apache基于域名的虚拟主机 别名

本文介绍如何通过配置实现一个IP地址对应多个网站的方法,包括使用基于域名的虚拟主机技术,并详细展示了如何设置Apache服务器来区分不同的域名,还介绍了如何为特定子目录设置别名。

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

基于域名的虚拟主机,一个IP对应多个网站
NameVirtualHost *

<VirtualHost *>
DocumentRoot d:/http/wwwroot
ServerName fading.cn
</VirtualHost>
<VirtualHost *>
DocumentRoot d:/http/wwwroot/Discuz!_6.0.0_SC_GBK/upload
ServerName dz6.fading.cn
</VirtualHost>

<VirtualHost *>
DocumentRoot d:/http/wwwroot/xspace/upload
ServerName x.fading.cn
</VirtualHost>
同时在C:\WINDOWS\system32\drivers\etc\hosts表中设置
127.0.0.1     localhost
127.0.0.1     fading.cn
127.0.0.1     dz6.fading.cn
127.0.0.1     x.fading.cn
或者修改DNS,多个域名指向同一个IP地址
访问路径:
http://fading.cn或localhost
http://dz6.fading.cn
http://x.fading.cn

别名alias:

Alias /dz6/ "d:/http/wwwroot/Discuz!_6.0.0_SC_GBK/upload/"
<Directory "d:/http/wwwroot/Discuz!_6.0.0_SC_GBK/upload">
    Options Indexes MultiViews
    AllowOverride None
    Order allow,deny
    Allow from all
</Directory>

Alias /x/ "d:/http/wwwroot/xspace/upload/"
<Directory "d:/http/wwwroot/xspace/upload">
    Options Indexes MultiViews
    AllowOverride None
    Order allow,deny
    Allow from all
</Directory>
访问的时候一定用
http://localhost/x/ 加上/
http://localhost/dz6/ 加上/
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值