1.vim httpd-vhosts.conf
<VirtualHost *:80> DocumentRoot "/data/www" ServerName www.123.com <Directory /data/www/abc/> AllowOverride AuthConfig AuthName "?" AuthType Basic AuthUserFile /data/.htpasswd require valid-user </Directory> </VirtualHost>
2.mkdir /data/.htpasswd
3. /usr/local/apache2/bin/htpasswd -c /data/.htpasswd user1
注意的是第一次创建用户是需要加-c的,第二次就不需要加-c,否则或覆盖
/usr/local/apache2/bin/htpasswd /data/.htpasswd user2
如果想要更改密码/usr/local/apache2/bin/htpasswd -m /data/.htpasswd user2
4.重启apache,访问www.123.com/abc