最近在我们这里在进行办公网规范化管理,其中一个方案就是用ftp的方式来代理邮件分发文件的方式,上传数据采用ftp方式,而实际的分发下载直接通过Apache的目录索引来下载,这其中有一些比较特殊的文件,需要使用密码来保护,因为用户众多,这个密码需要给用户自己修改,所以就采用了mod_auth_mysql+mysql来实现目录的相关认证(之所有没有用auth_bdb,因为Ubuntu的auth_bdb模块默认没有携带mysql驱动)。下面是安装和配置方法:
1、先安装mod_auth_mysql模块:
[bash] sudo apt-get install libapache2-mod-auth-mysql
2、启用mod_auth_mysql模块:
[bash] cd /etc/apache2/mods-enabled sudo ln -s ../mods-available/auth_mysql.load
3、假设您有个/sec目录需要特殊权限控制,在Apache配置文件或者.htaccess中:
[bash]
#Auth_MySQL_Info 需要连接的Mysql服务器IP 用户名 密码
Auth_MySQL_Info localhost apache apache_2008
#如果所有的目录认证使用同一数据库:
Auth_MySQL_General_DB htpasswd
<Directory /sec>
Options Indexes FollowSymLinks MultiViews
AuthType Basic
#注意下面两行事关闭缺省的Basic认证,不然会报打开认证文件错:pcfg_openfile() called with NULL filename
AuthUserFile /dev/null
AuthBasicAuthoritative off
AuthName "Security Area"
AuthMYSQL on
AuthMySQL_Authoritative on
AuthMySQL_Password_Table user_info
AuthMySQL_Group_Table user_info
AuthMySQL_Empty_Passwords off
#这里使用了明文的密码方式,如果要使用MySQL password()的方式,请用AuthMySQL_Encryption_Types Plaintext
#不过在Ubuntu中的libapache2-mod-auth-mysql不是采用Plaintext方式,
#apache会直接stack smashing,详细的情况可以看:https://bugs.launchpad.net/ubuntu/+source/libapache-mod-auth-mysql/+bug/150649
AuthMySQL_Encryption_Types Plaintext
AuthType Basic
#允许组为sec的用户访问
require group sec
</Directory>
4、创建用于认证的用户表
[sql]
create table user_info(
username VARCHAR(20),
passwd VARCHAR(50),
groups VARCHAR(20),
primary key (username)
)ENGINE=MyISAM;
insert into user_info values('u1','pass','sec');
然后,您就可以直接维护这个表来管理用户了
详细的mod_auth_mysql的使用文档,请看这里
O comments at "Apache+mod_auth_mysql+mysql+ubuntu 8.04"
Comment Now!