[root@localhost htdocs]# vim /usr/local/apache2.4/conf/extra/httpd-vhosts.conf
<VirtualHost *:80>
DocumentRoot "/data/wwwroot/apeng.com"
ServerName www.apeng.com
ServerAlias www.aling.com www.axin.com
ErrorLog "logs/apeng.com-error_log"
CustomLog "logs/apeng.com-access_log" common
<Directory /data/wwwroot/apeng.com>
AllowOverride AuthConfig
AuthName "www.apeng.com user auth"
AuthType Basic
AuthUserFile /data/.htpasswd
require valid-user
</Directory>
</VirtualHost>
# /usr/local/apache2.4/bin/htpasswd -c -m /data/.htpasswd apeng
# /usr/local/apache2.4/bin/htpasswd -m /data/.htpasswd aming
# /usr/local/apache2.4/bin/apachectl -t
# /usr/local/apache2.4/bin/apachectl graceful
# curl -x127.0.0.1:80 www.apeng.com //提示用户认证
# curl -x127.0.0.1:80 -uapeng aling.com //访问成功
在浏览器中访问(在hosts文件中添加相应的ip与域名对应关系)
输入用户名和密码即可访问
原文地址:http://blog.51cto.com/13480443/2072927