Apache中使用BasicAuth时,需要
mod_auth_basic.so
mod_authn_file.so
mod_authz_user.so
没有安装时:
/usr/local/httpd-shiva/bin/apxs -i -c -a /usr/local/src/httpd-2.2.2/modules/aaa/mod_authz_user.c
/usr/local/httpd-shiva/bin/apxs -i -c -a /usr/local/src/httpd-2.2.2/modules/aaa/mod_authn_file.c
/usr/local/httpd-shiva/bin/apxs -i -c -a /usr/local/src/httpd-2.2.2/modules/aaa/mod_auth.c
LoadModule authn_file_module modules/mod_authn_file.so
LoadModule authz_user_module modules/mod_authz_user.so
sudo /path/to/apache/bin/htpasswd -c /var/www/somewhere/passwd USERNAME
#input passwd for USERNAME
2 add this lines in httpd.conf
<Location /path_toadd_auth>
Order deny,allow
Allow from all
AuthType Basic
AuthName "Who R U?"
AuthBasicProvider file
AuthUserFile /var/www/somewhere/passwd
Require valid-user
</Location>
3 restart your apache.
mod_auth_basic.so
mod_authn_file.so
mod_authz_user.so
首先查看模块是否正常安装:
没有安装时:
/usr/local/httpd-shiva/bin/apxs -i -c -a /usr/local/src/httpd-2.2.2/modules/aaa/mod_authz_user.c
/usr/local/httpd-shiva/bin/apxs -i -c -a /usr/local/src/httpd-2.2.2/modules/aaa/mod_authn_file.c
/usr/local/httpd-shiva/bin/apxs -i -c -a /usr/local/src/httpd-2.2.2/modules/aaa/mod_auth.c
之后,编辑httpd.conf,添加:
LoadModule auth_basic_module modules/mod_auth_basic.soLoadModule authn_file_module modules/mod_authn_file.so
LoadModule authz_user_module modules/mod_authz_user.so
创建密码文件:
1 create passwd filesudo /path/to/apache/bin/htpasswd -c /var/www/somewhere/passwd USERNAME
#input passwd for USERNAME
2 add this lines in httpd.conf
<Location /path_toadd_auth>
Order deny,allow
Allow from all
AuthType Basic
AuthName "Who R U?"
AuthBasicProvider file
AuthUserFile /var/www/somewhere/passwd
Require valid-user
</Location>
3 restart your apache.