Apache: “ AuthType not set!”500错误

我已经有一段时间没有使用过 Apache httpd Web 服务器了。我正在为一个项目启动一个本地服务器,当我尝试请求 localhost/index.html 时,我得到一个500错误,我在错误日志中看到了这个:

[Tue Jan 21 09:23:58 2014] [crit] [client ::1] configuration error:  couldn't perform authentication. AuthType not set!: /index.html
[Tue Jan 21 09:23:58 2014] [error] an unknown filter was not added: DEFLATE
[Tue Jan 21 09:23:58 2014] [crit] [client ::1] configuration error:  couldn't perform authentication. AuthType not set!: /favicon.ico

看起来在 apache 配置中可能有2个错误,其中一个与“ AuthType not set!”另一个可能与“过滤器没有添加: DEFLATE”有关。我不知道这些是什么意思,也不知道从哪里开始挖。

一个基本的谷歌搜索显示 这个链接,这表明罪魁祸首可能是“要求所有批准”。我的 httpd.conf 中可能涉及到这一行。

<Directory "/var/www">
AllowOverride None
# Allow open access:
Require all granted
</Directory>

这个 apache 配置大部分都是在这个项目的生产环境中使用的,所以我知道它可以工作,只是当前不在我的工作站上。这意味着什么? 我接下来应该尝试什么?我确实尝试过注释“ RequiralGrant”并重新启动 apache,但没有用。

这个所以问题之后,我还加载了 mod _ authz _ host

LoadModule authz_host_module modules/mod_authz_host.so

并添加“允许从所有”,重新启动服务器,。但问题依然存在。紧缩的问题似乎是无关的,并很容易解决通过增加

LoadModule deflate_module modules/mod_deflate.so

问题仍然是,如何解决这个500错误?

[Tue Jan 21 09:44:20 2014] [crit] [client ::1]
configuration error:  couldn't perform authentication.
AuthType not set!: /index.html
150927 次浏览

I think that you have a version 2.4.x of Apache.

Have you sure that you load this 2 modules ? - mod_authn_core - mod_authz_core

LoadModule authn_core_module modules/mod_authn_core.so
LoadModule authz_core_module modules/mod_authz_core.so

PS : My recommendation for authorization and rights is (by default) :

LoadModule authn_file_module modules/mod_authn_file.so
LoadModule authn_core_module modules/mod_authn_core.so
LoadModule authz_host_module modules/mod_authz_host.so
LoadModule authz_groupfile_module modules/mod_authz_groupfile.so
LoadModule authz_user_module modules/mod_authz_user.so
LoadModule authz_core_module modules/mod_authz_core.so
LoadModule auth_basic_module modules/mod_auth_basic.so
LoadModule auth_digest_module modules/mod_auth_digest.so

Remove the line that says

Require all granted

it's only needed on Apache >=2.4

The problem here can be formulated another way: how do I make a config that works both in apache 2.2 and 2.4?

Require all granted is only in 2.4, but Allow all ... stops working in 2.4, and we want to be able to rollout a config that works in both.

The only solution I found, which I am not sure is the proper one, is to use:

# backwards compatibility with apache 2.2
Order allow,deny
Allow from all


# forward compatibility with apache 2.4
Require all granted
Satisfy Any

This should resolve your problem, or at least did for me. Now the problem will probably be much harder to solve if you have more complex access rules...

See also this fairly similar question. The Debian wiki also has useful instructions for supporting both 2.2 and 2.4.

You can try sudo a2enmod rewrite if you use it in your config.

Alternatively, this solution works with both Apache2 version < 2.4 as well as >= 2.4. Make sure that the "version" module is enabled:

a2enmod version

And then use this code instead:

<IfVersion < 2.4>
Allow from all
</IfVersion>
<IfVersion >= 2.4>
Require all granted
</IfVersion>

Just remove/comment the following line from your httpd.conf file (etc/httpd/conf)

Require all granted

This is needed till Apache Version 2.2 and is not required from thereon.