Nginx配置srcache_nginx模块搭配Redis建立缓存系统的方法


这篇“Nginx配置srcache_nginx模块搭配Redis建立缓存系统的方法”文章的知识点大部分人都不太理解,所以小编给大家总结了以下内容,内容详细,步骤清晰,具有一定的借鉴价值,希望大家阅读完这篇文章能有所收获,下面我们一起来看看这篇“Nginx配置srcache_nginx模块搭配Redis建立缓存系统的方法”文章吧。1. nginx模块2. redis安装配置
由于只把redis当做缓存使用,因此没有启用持久化。3. nginx配置4. 测试
没有做缓存状态:
有做缓存状态:
5. 响应头状态
第一次请求:
再次请求:
6. 查看redis是否缓存以及过期时间
ps:srcache-nginx-module模块指令说明:
srcache_fetch
语法:srcache_fetch ?
默认值:no
配置段:http, server, location, location if
查询缓存。返回200说明缓存命中,直接从缓存响应客户端请求。非200需要后端程序处理。
srcache_fetch_skip
语法:srcache_fetch_skip
默认值:srcache_fetch_skip 0
配置段:http, server, location, location if
支持nginx变量。当这个参数值不为空和不等于0,则从缓存取数据过程被无条件跳过。
srcache_store
语法:srcache_store ?
默认值:no
配置段:http, server, location 香港云主机, location if
将当前请求的响应存入缓存。可以使用srcache_store_skip和srcache_store_max_size指令禁用缓存。不管是响应状态行,响应头,响应体都会被缓存。默认情况下,下列特殊响应头不会被缓存:
connectionkeep-aliveproxy-authenticateproxy-authorizationtetrailerstransfer-encodingupgradeset-cookie可以使用srcache_store_pass_header、srcache_store_hide_header指令来控制哪些头要缓存哪些不要。注意:即使所有的响应数据被立即发送,当前的nginx请求生命周期未必完成,直到srcache_store子请求完成。这意味着服务器端延迟关闭tcp连接,或下一个请求服务发送同一个tcp连接。
srcache_store_max_size
语法:srcache_store_max_size
默认值:srcache_store_max_size 0
配置段:http, server, location, location if
当响应体超过该值,将不会缓存。
当后端缓存存储有对缓存数据做硬限制,这个指令非常有用。比如memcached服务器,上限是1m。
默认值0,不限制。
srcache_store_skip
语法:srcache_store_skip
默认值:srcache_store_skip 0
配置段:http, server, location, location if
支持nginx变量。当这个参数值不为空和不等于0,则从存入缓存过程被无条件跳过。
srcache_store_statuses
语法:srcache_store_statuses ..
默认值:srcache_store_statuses 200 301 302
配置段:http, server, location, location if
该指令控制那些状态码响应被缓存。
srcache_header_buffer_size
语法:srcache_header_buffer_size
默认值:srcache_header_buffer_size 4k/8k
配置段:http, server, location, location if
在序列化响应头时控制头缓冲大小。默认大小为页面大小,通常为4k或8k,取决于具体平台。
注意:该大小是以每个头的,因此,需要足够大来容纳最大响应头。
srcache_store_hide_header
语法:srcache_store_hide_header



默认值:no
配置段:http, server, location, location if
默认情况下,除了以下头缓存所有响应头:

connectionkeep-aliveproxy-authenticateproxy-authorizationtetrailerstransfer-encodingupgradeset-cookie可以隐藏多个响应头,不区分大小写。如srcache_store_pass_header
语法:srcache_store_pass_header



默认值:no
配置段:http, server, location, location if
默认情况下,除了以下头缓存所有响应头:

connectionkeep-aliveproxy-authenticateproxy-authorizationtetrailerstransfer-encodingupgradeset-cookie可以缓存多个响应头,不区分大小写。如srcache_methods
语法:srcache_methods
默认值:srcache_methods get head
配置段:http, server, location
srcache_ignore_content_encoding
语法:srcache_ignore_content_encoding on|off
默认值: srcache_ignore_content_encoding off
配置段:http, server, location, location if
内容是否编码。
建议后端服务器禁用gzip/deflate压缩。在nginx.conf配置:
srcache_request_cache_control
语法:srcache_request_cache_control on|off
默认值:srcache_request_cache_control off
配置段:http, server, location
当该指令为on时,请求头cache-control和pragma按照下面的方法处理:
1. srcache_fetch查询缓存操作时,当请求头cache-control: no-cache 、 pragma: no-cache 将跳过。
2. srcache_store存入缓存操作时,当请求头cache-control: no-store将跳过。
当该指令为off时,将禁用此功能,对于繁忙的站点依赖缓存加速被认为是最安全的。
srcache_response_cache_control
语法:srcache_response_cache_control on|off
默认值:srcache_response_cache_control on
配置段:http, server, location
当该指令为on时,响应头cache-control和expires按照下面的方法处理:
该指令优先级比srcache_store_no_store,srcache_store_no_cache,srcache_store_private高。
srcache_store_no_store
语法:srcache_store_no_store on|off
默认值:srcache_store_no_store off
配置段:http, server, location
开启该指令,将强制响应头cache-control: no-store。默认为关闭。
srcache_store_no_cache
语法:srcache_store_no_cache on|off
默认值:srcache_store_no_cache off
配置段:http, server, location
开启该指令,将强制响应头cache-control: no-cache。默认为关闭。
srcache_store_private
语法:srcache_store_private on|off
默认值:srcache_store_private off
配置段:http, server, location
开启该指令,将强制响应头cache-control: private。默认为关闭。
srcache_default_expire
语法:srcache_default_expire 以上就是关于“Nginx配置srcache_nginx模块搭配Redis建立缓存系统的方法”这篇文章的内容,相信大家都有了一定的了解,希望小编分享的内容对大家有帮助,若想了解更多相关的知识内容,请关注开发云行业资讯频道。

相关推荐: 如何分析MySQL中的REDO AHI latch锁

这篇文章将为大家详细讲解有关如何分析MySQL中的REDO AHI latch锁,文章内容质量较高,因此小编分享给大家做个参考,希望大家阅读完这篇文章后对相关知识有一定的了解。正文问: 我的系统里面有大事务,怎么辨别其中可能会出现的问题?在MYSQL中有一个共…

免责声明:本站发布的图片视频文字,以转载和分享为主,文章观点不代表本站立场,本站不承担相关法律责任;如果涉及侵权请联系邮箱:360163164@qq.com举报,并提供相关证据,经查实将立刻删除涉嫌侵权内容。

(0)
打赏 微信扫一扫 微信扫一扫
上一篇 10/23 11:10
下一篇 10/23 11:10

相关推荐