使用Apache 2.4并按照https://httpd.apache.org/docs/2.4/expr.html中的示例进行操作
这是我的代码
<If "!%{REQUEST_URI} =~ m#files/cache/static/[A-Za-z_\-0-9]+.cache#"> Header set foo-checksum "expr=%{md5:foo}" </If>
我现在只是在玩,但一旦我使用
Header set foo-checksum "expr=%{md5:foo}"
按照他们的例子 – 我明白了
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
在Apache的开始。 有任何想法吗? 我已经在expression式之外尝试过了,它给出了同样的错误
其他expression方式。
您需要使用Apache v2.4.10或更高版本,而Ubuntu 14.04 LTS随附v2.4.7,这很可能是您正在使用的。 文档在Header指令文档的开始处简要提到了这一点:
兼容性:2.4.7及更高版本中可用的SetIfEmpty ,2.4.10及更高版本中可用的expr =值
我跑了几台服务器来确认这个工作
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
但不在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.