【发布时间】:2016-12-14 00:05:38
【问题描述】:
我们正在运行 NGINX 服务器并且遇到了奇怪的缓存行为。该站点是运行最快缓存的 Wordpress。响应标头上的缓存控件始终显示:
max-age=0,无缓存,无存储,必须重新验证
网站是[boxChilli][https://www.boxchilli.com/]
我已尽一切努力让网站正确缓存,但我认为最好将其公开给社区。
【问题讨论】:
我们正在运行 NGINX 服务器并且遇到了奇怪的缓存行为。该站点是运行最快缓存的 Wordpress。响应标头上的缓存控件始终显示:
max-age=0,无缓存,无存储,必须重新验证
网站是[boxChilli][https://www.boxchilli.com/]
我已尽一切努力让网站正确缓存,但我认为最好将其公开给社区。
【问题讨论】:
因为 HTML 文件没有被缓存,所以它说 html 文件没有缓存,并且它的存储年龄为 max-age:0 表示内容总是从服务器提供。但是如果 nginx 配置如下,其余的内容应该被缓存。
请试试我写的这个教程。我详细解释了一切。 http://nucuta.com/wp-fastest-cache-configuration-for-nginx/
另外在 /etc/nginx/ 中的 nginx.conf 中使用它,您不必提及 text/html,因为 html 文件默认是压缩的。
gzip on;
gzip_disable "msie6";
gzip_vary on;
gzip_proxied any;
gzip_comp_level 6;
gzip_buffers 16 8k;
gzip_http_version 1.1;
gzip_types text/plain text/css application/json application/javascript text/xml application/xml application/xml+rss text/javascript;
并且在 /etc/nginx/sites-enabled/ 的默认文件中
location ~* \.(css|gif|ico|jpeg|jpg|js|png|woff|woff2|ttf|ttc|otf|eot)$ {
expires max;
log_not_found off;
}
【讨论】: