caching控制Apache的错误

我已经把httpd.conf

# 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! 

要使用Header指令,你需要加载mod_headers :

 sudo a2enmod headers 

3号线? 尝试将上面的configuration移到你的httpd.conf的末尾。 文件顶部还没有加载必要的模块。 在/etc/apache2/conf.d下的文件中也可以使用这样的代码片段,所以你不需要修改stock文件,但是你可以在之后解决这个问题。