Nginx-“强制" 200个缓存响应,而不是304个 [英] Nginx - "force" 200 cache response instead of 304

查看:602
本文介绍了Nginx-“强制" 200个缓存响应,而不是304个的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

是否可以通过某种方式强制使用200(缓存)响应,而不是不对静态文件进行修改的304?如果是这样,您可能会节省大量服务器请求,并加快返回访客的加载时间.

Is it possible somehow to force a 200 (cache) response instead of a 304 not modified for static files? If so you could potentially save a lot of server requests and speed up the loadtime considerbly for returning visitors.

推荐答案

我发现仅凭Expires不能正确设置行为.下面肯定有火了:

I've found Expires alone does not properly set the behavior. Below has been a sure fire:

# Set cache
expires 1M;
add_header Pragma public;
add_header Cache-Control "public";

需要在您所在的位置执行此操作.

This going in your location block desired..

我还认为,这方面有很多误导性信息.200在某种程度上与200(缓存)相同.

I also think there is a lot of misleading information out there on this.. That 200 is somehow the same as 200 (cache).

据我了解:

200-服务器请求-传输正常 200(缓存)-确定-没有服务器请求(来自缓存) 304-服务器请求-无转移(未修改)

200 - server request - transfer OK 200 (cache) - OK - no server request (from cache) 304 - server request - no transfer (not modified)

200(缓存),据我了解它根本不会发出服务器请求.

200 (cache) as I understand it does NOT make a server request at all.

这篇关于Nginx-“强制" 200个缓存响应,而不是304个的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆