我已经投入httpd配置文件
# 480 weeks
<filesmatch "\.(ico|pdf|flv|jpg|jpeg|png|gif|js|css|swf)$">
Header set Cache-Control "max-age=290304000, public"
</filesmatch>
# 2 days
<filesmatch "\.(xml|txt)$">
Header set Cache-Control "max-age=172800, public, must-revalidate"
</filesmatch>
# 2 hours
<filesmatch "\.(html|htm)$">
Header set Cache-Control "max-age=7200, must-revalidate"
</filesmatch>
但是当我运行/etc/init.d/apache restart
(在 Debian 6.0 中)时,我得到:
Syntax error on line 3 of /etc/apache2/httpd.conf:
Invalid command 'Header', perhaps misspelled or defined by a module not included in the server configuration
Action 'configtest' failed.
The Apache error log may have more information.
failed!
答案1
要使用Header
指令,您需要加载mod_headers:
sudo a2enmod headers
答案2
第 3 行?尝试将上述配置移至 httpd.conf 的末尾。必要的模块尚未加载到文件顶部。此外,最好将这样的代码片段放在 /etc/apache2/conf.d 下的文件中,这样您就不必修改现有文件,但您可以在之后处理这个问题。