Apache2和mysql授权

时间:2014-04-07 07:02:54

标签: mysql apache2 authorization

我正在尝试使用MySQL在Ubuntu 14.04上设置apache2的授权。

htaccess的:

AuthName "restricted area"
AuthType Basic
AuthBasicAuthoritative Off
AuthUserFile /dev/null

AuthMySQL On
AuthMySQL_Authoritative on
AuthMySQL_Host 10.30.200.1
AuthMySQL_Username name
AuthMySQL_Password pass
AuthMySQL_DB db
AuthMySQL_Password_Table access
AuthMySQL_Username_Field user
AuthMySQL_Password_Field password
AuthMySQL_Encryption_Types PHP_MD5
AuthMySQL_Empty_Passwords Off

Require valid-user

如果凭据是正确的,我会在error.log中收到401错误并且“[:error] [pid 1763] No required line available”。其他 - 只有401。

我做错了什么?

3 个答案:

答案 0 :(得分:2)

在同一版本上遇到完全相同的问题。

.htaccess上设置以下内容,对我有用: set AuthMySQL_Authoritative Off

答案 1 :(得分:1)

没有任何补丁关闭AuthMySQL_Authoritative并且做AuthMySQL_Where完全解决了这个问题。

答案 2 :(得分:0)

错误消息来自mod-auth-mysql模块本身。 我下载了源代码并查看了mod_auth_mysql.c文件

使用函数mysql_check_auth()接近文件末尾,您可以找到:

    if (!reqs_arr) {
    if (sec->authoritative) {
        APACHELOG(APLOG_ERR, r, "No requires line available");
        return HTTP_UNAUTHORIZED;
    } else {
        return DECLINED;
    }
}

经过一番研究后,我发现这个网站和以下补丁:
http://ehealth-aussie.blogspot.de/2013/07/compiling-modauthmysqlso-under-mountain.html
http://sourceforge.net/p/modauthmysql/patches/13/

但是ubuntu / debian模块基于版本2.2.0而不是3.0.0。 补丁的部分内容也包括在内:
MOD-AUTH-mysql_4.3.9-13.1ubuntu3.diff.gz

//编辑
首先,您必须设置AuthMySQL_Authoritative Off才能让mod_authz_user处理需要,就像有效用户一样。

如果你想通过mod-auth-mysql检查组,一个简单的修复就是在AuthMySQL_Where声明中移动用户和组要求,因为ap_requires不再存在,补丁将它设置为Null:

require group g1 g2

这变为:

AuthMySQL_Where "AND user_group IN ('g1', 'g2')"