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

    <Directory /www/www.kpop.com>

    Allowoverride authconfig

    authname "liuli test kpop"

    authtype basic

    authuserfile /www/.htpasswd

    require valid-user

    </Directory>

</VirtualHost>

2. 添加一个专用于认证的用户kpop,无需系统内存在

[root@minion-1 ~]# /usr/local/apache2.4/bin/htpasswd -c -m /www/.htpasswd kpop

3. 重启apache

[root@minion-1 ~]# /usr/local/apache2.4/bin/apachectl graceful