Ubuntu下Apache的身份验证

来源:互联网 发布:售电软件是什么 编辑:程序博客网 时间:2024/06/06 14:16
一.基于htpasswd创建的用户名密码的验证
1.创建用户名密码文件
touch -f  /tmp/shou/.passwdhtpasswd -b /tmp/shou/.passwd shou test1234
※htpasswd命令用法参照:http://hi.baidu.com/hellgrowl/item/75aa898fd97eb1c298255f9d
2.配置/etc/apache2/sites-available/default文件
Alias /test "/tmp/shou/test"<Directory "/tmp/shou/test">Options Indexes FollowSymLinks MultiViewsAllowOverride NoneOrder allow,denyallow from allAuthName "Authorization TEST(01)"AuthType BasicAuthUserFile /tmp/shou/.passwd Require valid-user</Directory>

二.基于MySQL数据库表中信息的验证
1.MySQL的验证,要求安装mod_auth_mysql模块。
sudo apt-get install libapache2-mod-auth-mysql

2.激活mode_auth_mysql模块

cd /etc/apache2/mods-enabledln -s ../mods-available/auth_mysql.load

3.创建数据库表,添加数据

CREATE TABLE tbl_user (    id INTEGER NOT NULL PRIMARY KEY AUTO_INCREMENT,    username VARCHAR(128) NOT NULL,    password VARCHAR(128) NOT NULL,    email VARCHAR(128) NOT NULL);INSERT INTO tbl_user (username, password, email) VALUES ('test1', 'pass1', 'test1@example.com');INSERT INTO tbl_user (username, password, email) VALUES ('test2', 'pass2', 'test2@example.com');

4.配置/etc/apache2/sites-available/default文件
Alias /test1 "/tmp/shou/test1"<Directory "/tmp/shou/test1">Options Indexes FollowSymLinks MultiViewsAllowOverride NoneOrder allow,denyallow from allAuthName "Authorization TEST(02)"AuthType                       BasicAuth_MySQL                     OnAuth_MySQL_Authoritative       OnAuth_MySQL_Host                localhostAuth_MySQL_Username            rootAuth_MySQL_Password            rootadminAuth_MySQL_DB                  testAuth_MySQL_Password_Table      tbl_userAuth_MySQL_Username_Field      usernameAuth_MySQL_Password_Field      passwordAuth_MySQL_Encryption_Types    PlaintextAuth_MySQL_Empty_Passwords     OffAuthBasicAuthoritative OffAuthUserFile /dev/nullRequire valid-user</Directory>