`
MauerSu
  • 浏览: 493296 次
  • 性别: Icon_minigender_1
  • 来自: 北京
文章分类
社区版块
存档分类
最新评论

nginx 设置 expires and Cache-Control

 
阅读更多
源:http://nginx.org/en/docs/http/ngx_http_headers_module.html
评:
add_header Cache-Control public;

Module ngx_http_headers_module

Example Configuration
Directives
     add_header
     expires
The ngx_http_headers_module module allows adding the “Expires” and “Cache-Control” header fields, and arbitrary fields, to a response header.

Example Configuration

expires    24h;
expires    modified +24h;
expires    @24h;
expires    0;
expires    -1;
expires    epoch;
add_header Cache-Control private;
Directives

Syntax: add_header name value [always];
Default: —
Context: http, server, location, if in location
Adds the specified field to a response header provided that the response code equals 200, 201, 204, 206, 301, 302, 303, 304, or 307. A value can contain variables.

There could be several add_header directives. These directives are inherited from the previous level if and only if there are no add_header directives defined on the current level.

If the always parameter is specified (1.7.5), the header field will be added regardless of the response code.

Syntax: expires [modified] time;
expires epoch | max | off;

Default:
expires off;
Context: http, server, location, if in location
Enables or disables adding or modifying the “Expires” and “Cache-Control” response header fields provided that the response code equals 200, 201, 204, 206, 301, 302, 303, 304, or 307. A parameter can be a positive or negative time.

A time in the “Expires” field is computed as a sum of the current time and time specified in the directive. If the modified parameter is used (0.7.0, 0.6.32) then time is computed as a sum of the file’s modification time and time specified in the directive.

In addition, it is possible to specify a time of the day using the “@” prefix (0.7.9, 0.6.34):

expires @15h30m;
The epoch parameter corresponds to the absolute time “Thu, 01 Jan 1970 00:00:01 GMT”. The contents of the “Cache-Control” field depends on the sign of the specified time:

time is negative — “Cache-Control: no-cache”.
time is positive or zero — “Cache-Control: max-age=t”, where t is a time specified in the directive, in seconds.
The max parameter sets “Expires” to the value “Thu, 31 Dec 2037 23:55:55 GMT”, and “Cache-Control” to 10 years.

The off parameter disables adding or modifying the “Expires” and “Cache-Control” response header fields.
分享到:
评论

相关推荐

    dokku-nginx-cache

    Dokku Nginx 缓存 在 Nginx 的代理缓存指令中连线。 用测试。 您的里程可能因香草 Dokku 而异。... X-Accel-Expires 、 Expires 、 Cache-Control 、 Set-Cookie和Vary设置响应的参数; X-Accel-Redirect执行到指定

    nginx expires控制页面缓存

    time值还控制”Cache-Control”的值:负数表示no-cache正数或零表示max-age=time epoch:指定“Expires”的值为 1January,1970,00:00:01 GMTmax:指定“Expires”的值为31December2037 23:59:59G

    详解Nginx服务器中HTTP Headers相关的模块配置使用

    ngx_http_headers_module模块提供了两个重要的指令add_header和expires,来添加 “Expires” 和 “Cache-Control” 头字段,对响应头添加任何域字段。add_header可以用来标示请求访问到哪台服务器上,这个也可以通过...

    nginx cache不缓存问题的原因与解决方案

    nginx.conf 部分内容: proxy_temp_path /nginx/cache/temp; proxy_cache_path /nginx/cache/path levels=1:2 keys_zone=cache_test:2048m ... proxy_ignore_headers X-Accel-Expires Expires Cache-Control Set-

    浏览器之HTTP缓存的那些事

    浏览器之HTTP缓存的那些事 什么是浏览器缓存 浏览器HTTP执行机制 缓存模式 缓存相关的Http Header Cache-Control Expires Last-Modified ETag

    nginx缓存不起作用问题解决方法

    header主要有如下: 代码如下:Cache-control:no-cache、no-store如果出现这两值,nginx缓存服务器是绝对不会缓存的 代码如下:Expires:1980-01-01如果出现日期比当前时间早,也不会缓存。 2. 解决不缓存方案 2.1 ...

    fastify-disablecache:固定插件以禁用客户端缓存

    受启发, fastify-disablecache插件设置以下响应标头和值以禁用客户端缓存: Surrogate-Control: no-store Cache-Control: no-store, no-cache, must-revalidate, proxy-revalidate Pragma: no-cache Expires: 0 您...

    讲解Nginx服务器中设置本地浏览器缓存的简单方法

    nginx可以通过 expires 指令来设置浏览器的Header 语法: expires [time|epoch|max|off] 默认值: expires off 作用域: http, server, location 使用本指令可以控制HTTP应答中的“Expires”和“Cache-Control”的头...

    如何在nginx中配置缓存静态文件

    这篇教程说明你应该怎样配置 nginx、设置 HTTP 头部过期时间,用 Cache-Control 中的 max-age 标记为静态文件(比如图片、 CSS 和 Javascript 文件)设置一个时间,这样用户的浏览器就会缓存这些文件。这样能节省...

    tattoo:一个用Go语言编写的简单博客系统

    directory and run tattoo使用Fast-CGI配置Nginx(快速CGI) 将以下代码添加到您的nginx站点配置文件中以使其工作: location /static/ {expires 1d;root YOUR_BLOG_PATH;add_header Cache-Control must-revalidate;...

Global site tag (gtag.js) - Google Analytics