參考:http://httpd.apache.org/docs/2.0/howto/auth.html
1.使用apache自帶的htpasswd創建密碼文件;
# htpasswd -c /home/lai/httpbasicpass admin
然后兩次輸入密碼即可。
# more /home/lai/httpbasicpass
admin:dH84ghAVHay72
2.在配置文件中最需要保護的部分<Directory>開啟basic認證
<Directory /data/webroot/mail_admin >
AllowOverride All
Order allow,deny
Allow from all
AuthType Basic
AuthName "Restricted Mail Management System"
AuthUserFile /home/lai/httpbasicpass
Require user admin
</Directory>
3.重啟apache
# /etc/init.d/apache2 restart