当前位置: 首页 > 学习 > 电脑学习 > 操作系统 > Linux > 安装经验 > 正文

mod_auth_mysql 在 Apache 2.0 下的安装和使用

http://www.zk168.com.cn  招考学习网 2006-3-11 10:49:57
-----------------------------------------------------------[交流]-[打印]-[发送]-[收藏]--
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
-----------------------------------------------------------[交流]-[打印]-[发送]-[收藏]--
最新入库:
 
·国外生活必备的英文词汇
·实用生活英语句子 174句
·唬老外的常用赞誉之辞语
·日常生活中商店译名参考
·在美生存常用习语
·实用生活英语二十六句
·年轻人常用口头禅
·去银行会用到的十句话
·中国文化的艺术精神_语言教育
·论苏拭的现实主义词风_语言教育
相关内容:
 
·大众传媒·大众文化·文化危机——丹
·知美·好美·乐美—谈美育的三个境界
·English Language: American or British?_语言教育
·How to improve the ability of listening, speaking,
·AN ANALYSIS OF LANGUAG_语言教育
·Published by the Corco_语言教育
·Language and Culture_语言教育
·教育与education探源_语言教育
·开口ABC 之 挑选礼物_语言教育
·闻言察意说CET听力_语言教育
网友点评:
 
会员名称:
密码:匿名 ·注册·忘记密码?
评论内容:
(最多300个字符)
  查看评论
友情提醒:
 1.库中的资料大都来自互联网、网友上传、各类书籍,在录入的过程中难免会出现错误,恳请网
 友来信指正!
 2.如果网友在本库中未能找到所需要的材料,请登陆到我们的论坛《招考学习网》版块!
 3.考友想加入招考学习网的编辑部,请发信到XueXiWang#Gmail.com(#改为@)附带个人简历
 4.如需转载请注明出处及作者,谢谢合作!
 5.如果您有更好的建议或意见请EMAIL:XueXiWang#Gmail.com (#改为@)
 6.凡标题中有注有“[NO]”字样均不含答案且答案整理中.
 7.如本库中转载文章涉及版权等问题,请相关网站或作者在两周内发邮件通知(EMAIL:  XueXiWang#Gmail.com (#改为@))我们,我们接到通知后立即删除该文章及链接!
你问我答 更多>>