HTTP頭處理?塊(HTTP Headers),這個(gè)模塊允許設(shè)置任意的HTTP頭
1) add_header
語(yǔ)法:add_header name value
默認(rèn)值:none
使用字段:http, server, location
2) expires
語(yǔ)法:expires [time|epoch|max|off]
默認(rèn)值:expires off
使用字段:http, server, location
這個(gè)指令控?是否在應(yīng)答中標(biāo)記一個(gè)過(guò)期時(shí)間,如果是,如何標(biāo)記。
off 將禁止修改頭部中的 Expires和Cache-Control字段。
Time控制“Cache-Control”的值,負(fù)數(shù)表示no-cache
epoch 將Expires頭設(shè)置為1 January, 1970 00:00:01 GMT。
max 將Expires頭設(shè)置為31 December 2037 23:59:59 GMT,將Cache-Control最大化到10 年。
例如設(shè)置php的文件類型過(guò)期時(shí)間設(shè)置為1個(gè)小時(shí):


設(shè)置php的文件類型為no-cache,不讓cache服務(wù)器緩存:


另外可以通過(guò)add_header設(shè)置相對(duì)應(yīng)的緩存策略,對(duì)于動(dòng)態(tài)的php文件設(shè)置為不緩存:
location ~ .*.php$ {
if ($request_uri !~ ^/dynamicimg/) {
add_header Cache-Control "no-cache";
add_header Pragma no-cache;
}
}