庞大资源库的计算机教程网站!
设为首页
加入收藏
总编信箱
投稿或申请专栏请先 [登 陆]
首页 操作系统 程序设计 图形图像 媒体动画 机械电子 WEB开发 数 据 库 办公系列 路由技术 网络原理 网络应用
认证考试 安全技术
首页>操作系统>Linux>安装经验>正文
资料搜索
Google搜索
Google
返回上级列表

推荐文章

快速保存网页中所有图片的方法
Windows中让光驱巧妙“隐身”技
防范非法用户入侵Win 2000/XP系
两款比较典型的ASP木马防范方法
有关表格边框的css语法整理
Windows XP中可以被禁用的服务
SQL Server导出导入数据方法
Javascript所有对象的属性的获
网页(HTML)中的特殊字符
与篮球共舞,尽显模式本色
QQ病毒的手工清除方法
Photoshop为极品美女打造性感睫
天衣无缝:IIS与PHP水火也相容
SQL Server存储过程编写和优化

mod_auth_mysql 在 Apache 2.0 下的安装和使用

 作者:徐永久    日期:2005-3-13
字号选择〖 〗/ 双击滚屏 单击停止   
mod_auth_mysql 是一款很好的基于数据库对 Apache 用户认证的模块,目前已经加入 Apache 模块库,而且最新版本支持 Apache 2.0。

这款软件已经在 FreeLAMP.com 上实施,现把实施过程作简要介绍。

这款软件的作者是 Ueli Heuer,其主页位于

http://www.heuer.org/mod_auth_mysql/.

安装说明十分简单,其英文原文可以看下面的连接:

http://www.heuer.org/mod_auth_mysql/INSTALL


这个模块目前只支持 Apache 2.0 ,安装采用 DSO 方式:

假设 Apache 2.0.36 安装于 /opt/httpd-2.0.36 ,那么运行的命令是:

/opt/httpd-2.0.36/bin/apxs -c -L /usr/local/mysql/lib/mysql mod_auth_mysql.c
/opt/httpd-2.0.36/bin/apxs -i mod_auth_mysql.la

你只要下载主页上的那个 mod_auth_mysql.c 就可以了。

然后在你的 MySQL 数据库上建立一个新的数据库,实际上使用原来存在的数据库也没有关系,只要新建的表名不和原来的表名重复就可以,但是为了安全考虑,建议建立单独的数据库。

建立数据库后,可以把下载主页上的那个 htpasswd.sql 导入到新的数据库,这个 SQL 文件建立了三个表:

user_info:用户信息
user_group:用户的组
host_info:主机信息


#
# Table structure for table `host_info`
#
# the fields created, updated, and isadmin are not needed by the module!
# they may help you creating a php-htpasswd frontend
#

CREATE TABLE host_info (
id int(14) NOT NULL auto_increment,
host char(255) NOT NULL default '',
host_group int(14) NOT NULL default '0',
created timestamp(14) NOT NULL,
updated timestamp(14) NOT NULL,
PRIMARY KEY (id),
KEY host (host)
) TYPE=MyISAM PACK_KEYS=1;
# --------------------------------------------------------

#
# Table structure for table `user_group`
#

CREATE TABLE user_group (
id int(14) NOT NULL auto_increment,
user_name char(50) NOT NULL default '',
user_group char(20) NOT NULL default '',
host_group int(14) default NULL,
created timestamp(14) NOT NULL,
updated timestamp(14) NOT NULL,
PRIMARY KEY (id),
KEY host_group (host_group),
KEY user_group (user_group)
) TYPE=MyISAM PACK_KEYS=1;
# --------------------------------------------------------

#
# Table structure for table `user_info`
#

CREATE TABLE user_info (
id int(14) NOT NULL auto_increment,
user_name char(30) NOT NULL default '',
user_passwd char(20) NOT NULL default '',
host_group int(14) NOT NULL default '0',
created timestamp(14) NOT NULL,
updated timestamp(14) NOT NULL,
isadmin tinyint(4) NOT NULL default '0',
PRIMARY KEY (id),
UNIQUE KEY user_name (user_name,host_group)
) TYPE=MyISAM PACK_KEYS=1;


从以上三个表的结构,我们可以看到,其中最主要的就是 host_group 的一致,
user_info 的 host_group 和 host_info 的 host_group 要对应起来,user_info 的其他字段,例如 isadmin,created,updated 等都还没有使用,用于以后扩展。
因此,一个简单的插入数据的例子就是:
insert into host_info (host) values ("www.freelamp.com");
insert into user_info (user_name,user_passwd) values ("albertxu",encrypt("my_log_passwd"));


然后修改 httpd.conf 加入:

LoadModule auth_mysql_module modules/mod_auth_mysql.so




AuthType Basic

AuthMySQLHost localhost ;连接数据库的主机地址,一般用本地连接,所以为 localhost
AuthMySQLUser apache_auth ;连接数据库的用户名
AuthMySQLPassword my_secret_pass ;连接数据库的口令
AuthMySQLDB apache ;数据库的名字

AuthSQLAuthoritative On
AuthSQLKeepAlive off





需要认证的目录下的 .htaccess 文件,要把 AuthUserFile 这项去掉。其他可以保持不变。

Authname "FreeLAMP.com Log Detail"
Authtype Basic
Require user albertxu


这样一个可以针对大型虚拟主机的认证系统就建立起来了。

最后需要特别说明的是:user_info 表中的 user_passwd 字段是采用 mysql 的 encrypt() 加密的,而不是 password() ,更不是明码。这个在文档上面没有说明,我电子邮件给 Ueli Heuer 先生,便很快得到了回答:

======================================================================
On Mon, 27 May 2002 23:20:30 +0800
"Xu" wrote:

Hi Albert,


The problem are the clertext passwords in the db. You need to encrypt this with the
encrypt() function from mysql or with the unix password crypt() function.

Did you check the errorlog form apache? mod_auth_mysql writes some hints if somethings
fails (e.g. dbconenction fails, host is not in the db, and so on

as an example:
[Mon May 27 17:52:04 2002] [error] [client 192.168.1.39] password mismatch on
deadeye.maillink.ch: http://test:versuch@deadeye.heuer.org/

Hope it helps

Greetz
Ueli
上一篇:一个快速自动安装Apache及其相关软件的Shell脚本    下一篇:Linux下面光盘刻录  
[发送给好友]  [关闭窗口]  [返回顶部]   转载请注明来源:www.it00.com   
特别声明: 本站除部分特别声明禁止转载的专稿外的其他文章可以自由转载,但请务必注明出处和原始作者。文章版权归文章原始作者所有。对于被本站转载文章的个人和网站,我们表示深深的谢意。如果本站转载的文章有版权问题请联系编辑人员,我们尽快予以更正。
责任编辑: 原点 投稿作者: 徐永久
信息来源: 网络 录入时间: 2005-3-13
关于我们 - 广告服务 - 版权申明 - 网站地图 - 联系方式 - 总编信箱 - 会员投稿