


mod_auth_mysql 在Apache 2.0下的安裝和使用
: mod_auth_mysql 是一款很好的基于數(shù)據(jù)庫(kù)對(duì)Apache
這款軟件已經(jīng)在 FreeLAMP.com 上實(shí)施,現(xiàn)把實(shí)施過(guò)程作簡(jiǎn)要介紹。
這款軟件的作者是 Ueli Heuer,其主頁(yè)位于
http://www.heuer.org/mod_auth_mysql/.
安裝說(shuō)明十分簡(jiǎn)單,其英文原文可以看下面的連接:
http://www.heuer.org/mod_auth_mysql/INSTALL
這個(gè)模塊目前只支持 Apache 2.0 ,安裝采用 DSO 方式:
假設(shè) Apache 2.0.36 安裝于 /opt/httpd-2.0.36 ,那么運(yùn)行的命令是:
/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
你只要下載主頁(yè)上的那個(gè) mod_auth_mysql.c 就可以了。
然后在你的 MySQL 數(shù)據(jù)庫(kù)上建立一個(gè)新的數(shù)據(jù)庫(kù),實(shí)際上使用原來(lái)存在的數(shù)據(jù)庫(kù)也沒有關(guān)系,只要新建的表名不和原來(lái)的表名重復(fù)就可以,但是為了安全考慮,建議建立單獨(dú)的數(shù)據(jù)庫(kù)。
建立數(shù)據(jù)庫(kù)后,可以把下載主頁(yè)上的那個(gè) htpasswd.sql 導(dǎo)入到新的數(shù)據(jù)庫(kù),這個(gè) SQL 文件建立了三個(gè)表:
user_info:用戶信息
user_group:用戶的組
host_info:主機(jī)信息
#
# 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;
從以上三個(gè)表的結(jié)構(gòu),我們可以看到,其中最主要的就是 host_group 的一致,
user_info 的 host_group 和 host_info 的 host_group 要對(duì)應(yīng)起來(lái),user_info 的其他字段,例如 isadmin,created,updated 等都還沒有使用,用于以后擴(kuò)展。
因此,一個(gè)簡(jiǎn)單的插入數(shù)據(jù)的例子就是:
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 ;連接數(shù)據(jù)庫(kù)的主機(jī)地址,一般用本地連接,所以為 localhost
AuthMySQLUser apache auth ;連接數(shù)據(jù)庫(kù)的用戶名
AuthMySQLPassword my_secret_pass ;連接數(shù)據(jù)庫(kù)的口令
AuthMySQLDB apache ;數(shù)據(jù)庫(kù)的名字
AuthSQLAuthoritative On
AuthSQLKeepAlive off
需要認(rèn)證的目錄下的 .htaccess 文件,要把 AuthUserFile 這項(xiàng)去掉。其他可以保持不變。
Authname "FreeLAMP.com Log Detail"
Authtype Basic
Require user albertxu
這樣一個(gè)可以針對(duì)大型虛擬主機(jī)的認(rèn)證系統(tǒng)就建立起來(lái)了。
最后需要特別說(shuō)明的是:user_info 表中的 user_passwd 字段是采用 mysql 的 encrypt()加密的,而不是 password() ,更不是明碼。這個(gè)在文檔上面沒有說(shuō)明,我電子郵件給 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
關(guān)鍵字:mod_auth_mysql Apache 2.0 安裝 使用
新文章:
- CentOS7下圖形配置網(wǎng)絡(luò)的方法
- CentOS 7如何添加刪除用戶
- 如何解決centos7雙系統(tǒng)后丟失windows啟動(dòng)項(xiàng)
- CentOS單網(wǎng)卡如何批量添加不同IP段
- CentOS下iconv命令的介紹
- Centos7 SSH密鑰登陸及密碼密鑰雙重驗(yàn)證詳解
- CentOS 7.1添加刪除用戶的方法
- CentOS查找/掃描局域網(wǎng)打印機(jī)IP講解
- CentOS7使用hostapd實(shí)現(xiàn)無(wú)AP模式的詳解
- su命令不能切換root的解決方法
- 解決VMware下CentOS7網(wǎng)絡(luò)重啟出錯(cuò)
- 解決Centos7雙系統(tǒng)后丟失windows啟動(dòng)項(xiàng)
- CentOS下如何避免文件覆蓋
- CentOS7和CentOS6系統(tǒng)有什么不同呢
- Centos 6.6默認(rèn)iptable規(guī)則詳解