Apache ExpiresDefault A0 不起作用

Apache ExpiresDefault A0 does not work

我正在设置 apache headers 并且不想缓存 PHP、CGI、Python 或任何动态文件。

我使用的服务器:Debian 9

我添加了这个配置:

# No caching for dynamic files
<filesMatch "\.(php|cgi|pl|htm)$">
    ExpiresDefault A0
    Header set Cache-Control "no-store, no-cache, must-revalidate, max-age=0"
    Header set Pragma "no-cache"
</filesMatch>

但显示以下错误:

AH00526: Syntax error on line 86 of /etc/apache2/conf-enabled/headers.conf: Invalid command 'ExpiresDefault', perhaps misspelled or defined by a module not included in the server configuration Action '-t' failed.

如何解决这个错误?

您需要启用mod_expiries。

取消注释 httpd.conf 中的以下行:

LoadModule expires_module modules/mod_expires.so

或者如果在基于 Debian 的系统上,则使用以下命令启用它:

a2enmod expires