apache2下使用mysql进行身份认证

服务器平台为ubuntu feisty,首先确认apache2已经安装好。
然后安装auth-mysql支持并启用此模块:

sudo aptitude install libapache2-mod-auth-mysql
sudo a2enmod auth_mysql

要建立一个数据库用于认证,并建立一个用户表存贮用户信息。

mysql -uroot
create database svn;
grant all on svn.* to svn@localhost identified by ‘mypwd’;
flush privileges;
use svn;
create table auth(
`username` varchar(25) NOT NULL default ”,
`passwd` varchar(25) NOT NULL default ”,
`groups` varchar(25) NOT NULL default ”,
PRIMARY KEY (`username`),
KEY `groups` (`groups`)
) ENGINE=MyISAM DEFAULT CHARSET=latin1;

然后修改site文件:

Auth_MySQL_Info localhost <auth_user> <password>

<Directory "<web directory>">
Options +Indexes FollowSymLinks MultiViews
AllowOverride AuthConfig Options FileInfo Limit
Order allow,deny
Allow from all
</Directory>

创建.htaccess文件:

AuthUserFile /dev/null
AuthBasicAuthoritative off
AuthMYSQL on
AuthMySQL_Authoritative on
AuthMySQL_DB svn
AuthMySQL_Password_Table auth
AuthMySQL_Group_Table auth
AuthMySQL_Empty_Passwords off
AuthMySQL_Encryption_Types Plaintext Crypt_DES
AuthName "<description>"
AuthType Basic

<Limit GET POST>
require valid-user
#or
require group group group1
</Limit>

注意问题:
注意这个部分AuthUserFile /dev/null
如果没有这行,apache的error_log中会出现这样的错误:

[error] [client ip] (9)Bad file descriptor: Could not open password file: (null)

如果没有AuthBasicAuthoritative off
会出现错误:

[error] [client ip] user yourusername not found:

参考:

http://www.howtoforge.com/mod_auth_mysql_apache2_debian

http://www.linuxmine.com/79991.html

This entry was posted in Linux and tagged , , , , . Bookmark the permalink.

One Response to apache2下使用mysql进行身份认证

  1. Pingback: LiangXu Wang » 安装subversion: ssl+auth_mysql+mod_svn

发表评论

电子邮件地址不会被公开。 必填项已用 * 标注

*

您可以使用这些 HTML 标签和属性: <a href="" title=""> <abbr title=""> <acronym title=""> <b> <blockquote cite=""> <cite> <code> <del datetime=""> <em> <i> <q cite=""> <strike> <strong>

Please copy the string RoOeHX to the field below:

以新浪微博帐号登录