最新消息:

web内容缓存 nginx高性能缓存详解

cache admin 3188浏览 0评论

内容缓存是显著提高web站点的性能最有效的方法之一。下面来说说nginx高性能缓存。

内容缓存的基本原则

nc-1

对GET请求进行缓存。

使用:浏览器缓存,内容分发网络和/或反向代理缓存。

nc-2

HTTP缓存机制:

1. 源服务器宣称的内容缓存能力。 主要是对http头信息来控制的。

2. 请求的客户端缓存能力,如GET请求。

nc-3

nginx对哪些进行缓存?

1. 缓存没有 Set-Cookie 的GET和HEAD的响应。

2. 通过定义独特的原始URL,如proxy_cache_key。

3. 通过定义缓存时间,如X-Accel-Expires、Cache-Control、Expires。

nginx 操作

nginx-highperformance-caching-4

nginx配置

nginx-highperformance-caching-5

缓存的过程

nginx的可在下列情况下使用陈旧的内容,通过proxy_cache_use_stale指令定义。

nginx-highperformance-caching-6

不仅仅对HTTP缓存,还有其他的,如:

1. FastCGI  功能很像HTTP

2. Memcache 检索memcached服务器的内容(必须预先填充)

3. uwsgi and SCGI

如何理解这些

nginx-highperformance-caching-7

缓存仪表

$upstrem_cache_status 变量值有:MISS、BYPASS、EXPIRED、STALE、UPDATING、REVALDATED、HIT。

nginx-highperformance-caching-8

nginx-highperformance-caching-9

扩展状态监控

在nginx上缓存内容

nginx-highperformance-caching-10

它是如何工作的?

1. nginx是使用基于磁盘的持久性缓存

2. 关注下面几点:

  • 内容是如何存储在缓存?
  • 缓存是如何在启动时加载的?
  • 缓存过期修剪
  • 人工清理缓存内容

nginx-highperformance-caching-11

缓存内容是如何存储的?

首先需要定义proxy_cache_path。

  • 定义缓存key,proxy_cahce_key
  • 获取内容到缓存中,然后检查MD5值
  • 验证

nginx-highperformance-caching-12

从磁盘加载缓存

nginx-highperformance-caching-13

管理磁盘缓存

nginx-highperformance-caching-14

清除磁盘内容

控制缓存

nginx-highperformance-caching-15

延迟缓存  proxy_cache_min_uses 节省磁盘写入

缓存重新验证 proxy_cache_revalidate 节省上行带宽和磁盘写入

nginx-highperformance-caching-16

缓存时间控制

nginx-highperformance-caching-17

nginx-highperformance-caching-18

多个缓存

为什么缓存

nginx-highperformance-caching-19

提高网页速度

nginx-highperformance-caching-20

nginx-highperformance-caching-21

nginx-highperformance-caching-22

 

参考内容:

NGINX High-performance Caching from Nginx, Inc.

HTTP caching basics:http://www.tommylacroix.com/2008/07/17/http-caching-basics/

HTTP cache headers:http://www.mobify.com/blog/beginners-guide-to-http-cache-headers/

HTTP:https://www.varnish-software.com/static/book/HTTP.html

转载请注明:爱开源 » web内容缓存 nginx高性能缓存详解

您必须 登录 才能发表评论!