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

被折叠的 条评论
为什么被折叠?



