在apache http server中配置虚拟机和虚拟路径的方法

本文介绍如何在Apache服务器中配置虚拟主机及访问控制。通过编辑httpd.conf文件添加虚拟主机设置,实现不同域名指向不同的目录,并设置基本认证保护敏感资源。

1.配置虚拟机
打开httpd.conf文件,在DocumentRoot "C:/Program Files/Apache Software Foundation/Apache2.2/htdocs"后面添加如下:

<VirtualHost *:80>
DocumentRoot "D:/mydir"
ServerName test
DirectoryIndex phpinfo.php index.php index.html index.htm
<Directory "D:/mydir">
    Options Indexes FollowSymLinks Multiviews
    AllowOverride All
    Order Allow,Deny
    Allow from all
</Directory>
</Virtualhost>

2.配置虚拟路径

添加以下代码
Alias / "D:/mydir/"
<Directory "D:/mydir">
AllowOverride All
Options Indexes MultiViews
Order allow,deny
Allow from all
AuthType Basic
AuthName "Please login:"
AuthUserFile "C:/Program Files/Apache Software Foundation/Apache2.2/bin/userpwd.txt"
Require User user

</Directory>

在bin文件夹下,在控制台输入htpasswd.exe -c userpwd.txt user

password

password

这样就创建了一个访问控制的用户user,通过密码password登陆http。

 

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值