1. 在网站的目录里添加directory属性
[root@minion-1 ~]# vi /usr/local/apache2.4/conf/extra/httpd-vhosts.conf
<VirtualHost *:80>
DocumentRoot "/www/www.kpop.com"
ServerName www.kpop.com
ServerAlias www.kpop.cn
ErrorLog "logs/www.kpop.com-error_log"
CustomLog "logs/www.kpop.com-access_log" common
<<filesmatch admin.php>>
Allowoverride authconfig
authname "liuli test kpop"
authtype basic
authuserfile /www/.htpasswd
require valid-user
</filesmatch>
</VirtualHost>
2. 编辑网站下的admin.php
[root@minion-1 ~]# vi /www/www.kpop.com/admin.php
3. 添加一个专用于认证的用户kpop,无需系统内存在
[root@minion-1 ~]# /usr/local/apache2.4/bin/htpasswd -c -m /www/.htpasswd kpop
4. 重启apache
[root@minion-1 ~]# /usr/local/apache2.4/bin/apachectl graceful