大网数据广告活动
服务器运维问答

Apache 2.4 Unrecognized header format %

· 52CE 我爱测

Using Apache 2.4 and followed the examples here https://httpd.apache.org/docs/2.4/expr.html Here is my code <If "!%{REQUEST_URI} =~ m#files/cache/static/[A-Za-z_\-0-9]+.cache#"> Header set foo-checksum "expr=%{md5:foo}" </If> I'm…

问题原文

原帖链接 · TheBritishAreComing · CC BY-SA 3.0

Using Apache 2.4 and followed the examples here https://httpd.apache.org/docs/2.4/expr.html

Here is my code

<If "!%{REQUEST_URI} =~ m#files/cache/static/[A-Za-z_\-0-9]+.cache#"> 
    Header set foo-checksum "expr=%{md5:foo}"
</If>

I'm just playing at the moment but as soon as I use

    Header set foo-checksum "expr=%{md5:foo}"

As per their example - I get

AH00526: Syntax error on line 130 of /etc/httpd/conf/httpd.conf:
httpd[19459]: Unrecognized header format %
httpd.service: main process exited, code=exited, status=1/FAILURE

On apache start. Any ideas? I've tried it outside of an expression as well and it gives the same error

Other expressions work.

社区高分解答

原帖链接 · MoeBrowne · CC BY-SA 3.0

You need to be using Apache v2.4.10 or above and as Ubuntu 14.04 LTS ships with v2.4.7 this is most likely what you are using. The documentation mentions this briefly at the start of the Header directive docs:

Compatibility: SetIfEmpty available in 2.4.7 and later, expr=value available in 2.4.10 and later

I ran up a couple of servers to confirm this works

Apache v2.4.12:

root@ubuntu-server:~# lsb_release -a
No LSB modules are available.
Distributor ID: Ubuntu
Description:    Ubuntu 15.10
Release:    15.10
Codename:   wily

root@ubuntu-server:~# cat /etc/apache2/sites-enabled/000-default.conf 
<VirtualHost *:80>
Header set foo-checksum "expr=%{md5:foo}"
</VirtualHost>

root@ubuntu-server:~# apachectl -v
Server version: Apache/2.4.12 (Ubuntu)
Server built:   Jul 24 2015 15:59:00

root@ubuntu-server:~# service apache2 reload

root@ubuntu-server:~# curl -I localhost
HTTP/1.1 200 OK
Date: Mon, 07 Mar 2016 21:15:38 GMT
Server: Apache/2.4.12 (Ubuntu)
Last-Modified: Mon, 07 Mar 2016 20:57:04 GMT
ETag: "2c39-52d7bb502f118"
Accept-Ranges: bytes
Content-Length: 11321
Vary: Accept-Encoding
foo-checksum: acbd18db4cc2f85cedef654fccc4a4d8
Content-Type: text/html

but not on Apache v2.4.7:

root@ubuntu-server:~# lsb_release -a
No LSB modules are available.
Distributor ID: Ubuntu
Description:    Ubuntu 14.04.4 LTS
Release:    14.04
Codename:   trusty

root@ubuntu-server:~# cat /etc/apache2/sites-enabled/000-default.conf 
<VirtualHost *:80>
Header set foo-checksum "expr=%{md5:foo}"
</VirtualHost>

root@ubuntu-server:~# apachectl -v
Server version: Apache/2.4.7 (Ubuntu)
Server built:   Jan 14 2016 17:45:23

root@ubuntu-server:~# service apache2 reload
 * Reloading web server apache2                                                                                                                   * 
 * The apache2 configtest failed. Not doing anything.
Output of config test was:
AH00526: Syntax error on line 2 of /etc/apache2/sites-enabled/000-default.conf:
Unrecognized header format %
Action 'configtest' failed.
The Apache error log may have more information.

摘自公开归档,保留原文语言,版式经整理,外部媒体与邮箱地址已移除。

资料来源与适用范围

资料来源
Server Fault
适用范围
以原帖系统、软件版本与发布日期为准(2016-01-11)
内容语言
中文;命令、路径和错误标识保留技术原文
本地收录日期
2026-11-15
授权说明
CC BY-SA 3.0

正文与所需资源由本站本地存储。查看来源及更新记录 ↗

请按适用版本和实际日志确认原因;本站没有对每一种系统或设备逐项执行文中的操作。