nginx proxy_cache 配置

利用nginx proxy_cache进行网站缓存托底配置 众所周知nginx proxy_cache可以对请求的response进行缓存,起到类似CDN的作用,甚至有比CDN提供更多的功能,还可以用来缓存托底数据,当后台tomcat挂掉的时候,nginx直接将缓存中的托底数据返回给用户。 阅读详情

众所周知nginx proxy_cache可以对请求的response进行缓存,起到类似CDN的作用,甚至有比CDN提供更多的功能,还可以用来缓存托底数据,当后台tomcat挂掉的时候,nginx直接将缓存中的托底数据返回给用户。

直接贴上详细配置

upstream tomcat_localhost {

//注意此处超时时间不要设置太长
server 127.0.0.1:8080 weight=10 max_fails=1 fail_timeout=1s;
}

1.nginx缓存空间配置,该配置定义在nginx配置文件的server上方即可

#proxy_cache_path : 代理缓存的缓存文件路径,/export/Data/huishou.jd.local 该目录一定要提前创建好,否则配置文件检测会失败,并且该目录不能删除,删除后缓存消失

# levels=1:2  nginx会在上述配置的缓存文件路径下再创建两级目录,第一级目录命名为一个字符,第二级目录命名为2个字符

#keys_zone=my_cache:100m max_size=100m 定义缓存的名称和缓存大小 ,缓存的名称会在下面的location中使用,缓存大小可以结合自己服务器内存和系统需要缓存的内容大小进行考虑设置

# inactive=1d 缓存文件的有效时间,缓存到达该设置的时间后无论是否在使用都会从缓存路径下移除,然后回源获取新数据在生成缓存文件

proxy_cache_path /export/Datal/cache levels=1:2 keys_zone=my_cache:100m max_size=300m inactive=1d;

 

2.nginx缓存托底拦截配置,该配置在具体的location内

location / {

#配置上面定义的缓存空间名称,必选配置
proxy_cache my_cache;
#设置缓存的key,还可以根据url中的参数进行自定义;$args表示所有参数,也可以使用其中的一个参数,例如:$arg_name,表示只取参数列表中的name参数,此处可以灵活配置,必选配置

proxy_cache_key $host$uri$is_args$args;

#设置绕过缓存的请求url,即url中包含该配置的值,则该请求不从缓存中获取数据,非必须配置

proxy_cache_bypass $arg_noCache;

#根据响应码设置缓存时间,超过这个时间即使缓存文件中有缓存数据,nginx也会回源请求新数据。此处的值还可以根据response中header中设置的Cache-Control缓存时间进行控制,header中的设置优先级最高,如果此处和header都没有设置缓存时间,则nginx不会生成缓存文件,非必须配置,如果此处不做配置,header中必须有设置
proxy_cache_valid 200 1m;

#此处是托底配置,旧的总比出错强,当nginx请求后台服务器报错的时候,如果返回配置的错误响应码,nginx则直接取缓存文件中的旧数据返回给用户,托底使用必选配置
proxy_cache_use_stale error timeout updating http_500 http_502 http_503 http_504;

#缓存并发锁,当nginx缓存没有命中的时候只有一个请求回源tomcat请求数据,其他请求会等待。非必选配置
proxy_cache_lock on;

#等待锁超时时间设置 非必选配置
proxy_cache_lock_timeout 1s;
proxy_pass tomcat_localhost ;
}

3.经过上述配置后,nginx的缓存托底配置就完成了,在缓存文件有效时间内,即使后台tomcat挂掉,被缓存过的页面或接口也能正常提供服务。

 


【异常】Nginx报错: [emerg] unknown directive ““ in /usr/local/nginx/nginx.conf:xx Nginx配置报错"[emerg] unknown directive"常见问题摘要:当执行nginx -s reload时出现此错误,通常是由于配置文件中存在多余空格或空行导致的语法问题。错误信息会显示发生问题的具体行号(xx)。解决方法需要仔细检查该行及相邻行的配置内容,删除多余空格或空行后重新保存即可。此类问题多因编辑时不小心多输入字符引起,细心检查重写配置即可解决。 阅读详情

相关推荐

Nginx的缓存服务器proxy_cache配置

proxy_busy_buffers_size 开启缓冲响应的功能以后,在没有读到全部响应的情况下,写缓冲到达一定大小时,nginx一定会向客户端发送响应,直到缓冲小于此值。Nginx的缓存加速功能是由proxy_cache(用于反向代理和静态缓存)和fastcgi_cache(PHP动态缓存)两个功能模块完成。proxy_pass nginx缓存里拿不到资源,向该地址转发请求,拿到新的资源,并进行缓存。proxy_cache 指定用于页面缓存的共享内存,对应http层设置的keys_zone。

hanzhuhuaa的博客 290

Nginx的缓存模块proxy_cache

转自:https://blog.youkuaiyun.com/jcwkyl/article/details/6079358 Nginx缓存模块proxy_cache 缓存配置语法 缓存过期周期 定义缓存的键,缓存的维度 Nginx缓存配置示例 准备web节点 准备Proxy节点 访问测试 清理Nginx缓存方式 配置某些页面不缓存,并配置缓存日志 部分缓存测试 缓存配置语法 Syntax: prox...

shengerjianku的专栏 1486

Nginx proxy_cache 缓存配置

原文地址:https://blog.youkuaiyun.com/dengjiexian123/article/details/53386586/ 前言: 由于本人工作原因,涉及到网络直播领域,其中视频的回放下载,涉及到了一些视频下载方面的技术。针对于一个完整视频的下载,目前市面上的主流做法是,先将整个视频流切片,存储到文件服务器中,在用户需要观看回放视频时。通过一个视频回源服务器,去文件服务器中逐个请求...

杨春建的博客 963

nginx: [emerg] "proxy_cache_path" directive is not allowed here in /usr/local/nginx/conf/nginx.conf:...

1、它只能使用于http{  }部分,把proxy_cache_path放置于http部分即可解决此问题。注意图示的上下文  

weixin_33691700的博客 4084

芯片设计中的“隐形杀手”:手把手教你理解并优化互连寄生参数(以SPEF/DSPF为例)

本文深入探讨了芯片设计中互连寄生参数的影响及优化策略,特别关注SPEF/DSPF文件解析与静态时序分析。通过实际案例展示了耦合电容对时序收敛的关键影响,并提供从定位到优化的完整解决方案,助力工程师应对先进工艺下的设计挑战。

weixin_30687051的博客 597

华为模拟器eNSP练习题 - HCIA综合实验

华为模拟器eNSP练习题 - HCIA综合实验 题目要求 ISP路由器只能配置IP地址,之后不得进行其他任何配置; 整个内部网络基于192.168.1.0/24进行地址规划; R1/R2之间启动OSPF协议,单区域; PC1-PC4自动获取IP地址; PC1不能telnet R1,PC1外的其他内网pc可以; PC1-PC4可以访问PC5,R2的公网接口只拥有一个公有IP12.0.0.1; 外部的client可以通过域名www.ensp.com访问http server; ISP路由telnet 12.0

炸鸡店老板z的博客 9867

Nginx反向代理缓存(proxy_cache配置)

实验环境 IP 服务 备注 192.168.1.10 nginx 用作代理服务器 192.168.1.20 nginx 安装Nginx、关闭防火墙 systemctl stop firewalld && systemctl disable firewalld && setenforce 0 yum -y install epel-release yum -y install nginx 修改nginx配置文件、添加proxy_cache配置 192

小啊宇的博客 2908

DEAP数据集实战:用PyTorch搭建DNN/CNN脑电情绪识别模型(附完整代码)

本文详细介绍了如何使用PyTorch搭建DNN和CNN模型对DEAP数据集进行脑电情绪识别。从数据预处理到模型架构设计,再到训练优化和部署,提供了完整的实战指南和代码示例,帮助研究者快速掌握脑电信号识别技术。

k8l9m0n的博客 392

nginx proxy_cache 缓存配置

前言: 由于本人工作原因,涉及到网络直播领域,其中视频的回放下载,涉及到了一些视频下载方面的技术。针对于一个完整视频的下载,目前市面上的主流做法是,先将整个视频流切片,存储到文件服务器中,在用户需要观看回放视频时。通过一个视频回源服务器,去文件服务器中逐个请求切片,返回给用户播放。 今天着重探讨的是关于回源服务器缓存的配置以及合理的缓存策略。 通过给回源服务器配置缓存的案例,详细讲解一整套缓

dengjiexian123的专栏 7万+

激光三角测量法:斜射与直射式技术的原理与应用解析

本文深入解析激光三角测量法中斜射式与直射式技术的原理、应用及对比。斜射式适用于高精度小范围测量,尤其擅长处理反光表面;直射式则适合大范围位移检测,结构更简单。文章详细介绍了两种技术的光路分析、数学建模、应用场景及选型建议,并探讨了系统校准与误差分析方法,为工业检测领域提供实用参考。

weixin_29280219的博客 414

告别GUI点点点:Formality形式化验证的TCL脚本自动化实战(附完整脚本)

本文详细介绍了如何通过TCL脚本实现Formality形式化验证的全流程自动化,显著提升验证效率并降低错误率。内容涵盖脚本框架解析、参数化设计、验证报告生成及团队协作策略,特别适合芯片设计工程师摆脱传统GUI操作,实现300%以上的效率提升。

weixin_33737134的博客 282

nginx Proxy Cache 配置

总结一下 proxy cache 设置的常用指令及使用方法: proxy_cache proxy_cache zone | off 配置一块公用的内存区域的名称,该区域可以存放缓存的索引数据。注意:zone 代表用于存放缓存索引的内存区域的名称(需要使用 proxy_cache_path指令设置);off 代表关闭Proxy Cache功能 proxy_cac...

weixin_30575309的博客 208

如何利用gretna软件计算脑网络全局属性(聚类系数,小世界属性,最短路径),局部属性指标(度,度分布,节点效率),如何理解网络稀疏度

grena工具箱被设计用于fMRI数据的图论网络分析。它是一套MATLAB函数和基于MATLAB的接口,用于常规的fMRI预处理,用于计算和统计分析最常用的网络指标,如小世界参数、效率、度、间性、关联性、层级性、同步性和模块化。......

从事脑科学核磁共振方法学研究,在Nature communications等权威期刊发表研究论文,熟练掌握磁共振处理方法和统计学方法,欢迎大家和我交流。 9173

nginx proxy_cache 缓存配置[转]

前言: 由于本人工作原因,涉及到网络直播领域,其中视频的回放下载,涉及到了一些视频下载方面的技术。针对于一个完整视频的下载,目前市面上的主流做法是,先将整个视频流切片,存储到文件服务器中,在用户需要观看回放视频时。通过一个视频回源服务器,去文件服务器中逐个请求切片,返回给用户播放。 今天着重探讨的是关于回源服务器缓存的配置以及合理的缓存策略。 通过给回源服务器配置缓存的案例,详细讲解一整套缓存配置机制,并且可沿用到其他任何缓存配置场景中。 今天的讲解分为四点: 回源服务器的工作是啥 为啥需.

weixin_46742102的博客 1329

勇攀数字高峰

摘要:该题目要求在数字地形图中寻找从最低点到最高点的所有严格递增登山路径。采用DFS深度优先搜索结合回溯算法,通过标记已访问位置并检查高度差限制(0<diff≤maxDiff)来遍历所有可能路径。算法首先确定起点(最低点)和终点(最高点),然后进行DFS搜索,每步移动需满足四个方向的合法移动且高度严格递增。最终输出符合条件的路径总数。提供了C++、Java和Python三种实现方案。

面试高手的博客 621

C#工业通信完整项目实战:从协议解析到数据库存储,打造工业级全链路数据闭环(完整可复用源码)

工业自动化的核心诉求是「数据闭环」:从工业设备采集真实生产数据 → 解析校验获得有效数据 → 持久化存储到数据库形成生产台账 → 数据分析/报表展示/异常预警,形成采集→解析→处理→存储→应用的全链路数据流转,这也是工业上位机开发的终极落地形态,区别于单纯的「数据采集」demo。本次实战是一套工业级完整投产级项目,基于C# WinForm + .NET Framework 4.8(工业标配)✅双通信链路完美适配:同时封装TCP网口 + 串口(RS232/485)

这里只有干货:从 Modbus 通信到 MES 对接,从 YOLO 训练到工控机部署,带你搞定工业软件开发全流程。 1035

架构设计 - Nginx Proxy Cache 缓存配置

应用缓存体系 nginx proxy cache 三级缓存

suiusoar 1001

LinePhone3.2.7(android端最新版本) sip客户端

SIP客户端For android:LinePhone3.2.7(最新版本),官网地址:http://www.linphone.org/

nginx配置Proxy Cache缓存的12个指令

白小石的IT刷怪秘籍 2017-05-09 11:11 proxy Buffer开启后才能使用proxy_cachhe。将已有的数据在内存中建立缓存数据,缓存过期不销毁硬盘的数据,nginx接受到被代理服务器的数据后,通过proxy buffer机制将数据传递给客户端,通过proxy cache将数据缓存到本地硬盘 1. proxy_cache zone | off; 配置一块公

u011277123的博客 2179

深度学习工具包 DeepLearningToolbox

深度学习工具包Deprecation notice.-----This toolbox is outdated and no longer maintained.There are much better tools available for deep learning than this toolbox, e.g. [Theano](http://deeplearning.net/software/theano/), [torch](http://torch.ch/) or [tensorflow](http://www.tensorflow.org/)I would suggest you use one of the tools mentioned above rather than use this toolbox.Best, Rasmus.DeepLearnToolbox================A Matlab toolbox for Deep Learning.Deep Learning is a new subfield of machine learning that focuses on learning deep hierarchical models of data.It is inspired by the human brain's apparent deep (layered, hierarchical) architecture.A good overview of the theory of Deep Learning theory is[Learning Deep Architectures for AI](http://www.iro.umontreal.ca/~bengioy/papers/ftml_book.pdf)For a more informal introduction, see the following videos by Geoffrey Hinton and Andrew Ng.* [The Next Generation of Neural Networks](http://www.youtube.com/watch?v=AyzOUbkUf3M) (Hinton, 2007)* [Recent Developments in Deep Learning](http://www.youtube.com/watch?v=VdIURAu1-aU) (Hinton, 2010)* [Unsupervised Feature Learning and Deep Learning](http://www.youtube.com/watch?v=ZmNOAtZIgIk) (Ng, 2011)If you use this toolbox in your research please cite [Prediction as a candidate for learning deep hierarchical models of data](http://www2.imm.dtu.dk/pubdb/views/publication_details.php?id=6284)```@MASTERSTHESIS\{IMM2012-06284, author = "R. B. Palm", title = "Prediction as a candidate for learning deep hierarchical models of data", year = "2012",}```Contact: rasmusbergpalm at gmail dot comDirectories included in the toolbox-----------------------------------`NN/` - A library for Feedforward Backpropagation Neural Networks`CNN/` - A library for Convolutional Neural Networks`DBN/` - A library for Deep Belief Networks`SAE/` - A library for Stacked Auto-Encoders`CAE/` - A library for Convolutional Auto-Encoders`util/` - Utility functions used by the libraries`data/` - Data used by the examples`tests/` - unit tests to verify toolbox is workingFor references on each library check REFS.mdSetup-----1. Download.2. addpath(genpath('DeepLearnToolbox'));Example: Deep Belief Network---------------------```matlabfunction test_example_DBNload mnist_uint8;train_x = double(train_x) / 255;test_x = double(test_x) / 255;train_y = double(train_y);test_y = double(test_y);%% ex1 train a 100 hidden unit RBM and visualize its weightsrand('state',0)dbn.sizes = [100];opts.numepochs = 1;opts.batchsize = 100;opts.momentum = 0;opts.alpha = 1;dbn = dbnsetup(dbn, train_x, opts);dbn = dbntrain(dbn, train_x, opts);figure; visualize(dbn.rbm{1}.W'); % Visualize the RBM weights%% ex2 train a 100-100 hidden unit DBN and use its weights to initialize a NNrand('state',0)%train dbndbn.sizes = [100 100];opts.numepochs = 1;opts.batchsize = 100;opts.momentum = 0;opts.alpha = 1;dbn = dbnsetup(dbn, train_x, opts);dbn = dbntrain(dbn, train_x, opts);%unfold dbn to nnnn = dbnunfoldtonn(dbn, 10);nn.activation_function = 'sigm';%train nnopts.numepochs = 1;opts.batchsize = 100;nn = nntrain(nn, train_x, train_y, opts);[er, bad] = nntest(nn, test_x, test_y);assert(er < 0.10, 'Too big error');```Example: Stacked Auto-Encoders---------------------```matlabfunction test_example_SAEload mnist_uint8;train_x = double(train_x)/255;test_x = double(test_x)/255;train_y = double(train_y);test_y = double(test_y);%% ex1 train a 100 hidden unit SDAE and use it to initialize a FFNN% Setup and train a stacked denoising autoencoder (SDAE)rand('state',0)sae = saesetup([784 100]);sae.ae{1}.activation_function = 'sigm';sae.ae{1}.learningRate = 1;sae.ae{1}.inputZeroMaskedFraction = 0.5;opts.numepochs = 1;opts.batchsize = 100;sae = saetrain(sae, train_x, opts);visualize(sae.ae{1}.W{1}(:,2:end)')% Use the SDAE to initialize a FFNNnn = nnsetup([784 100 10]);nn.activation_function = 'sigm';nn.learningRate = 1;nn.W{1} = sae.ae{1}.W{1};% Train the FFNNopts.numepochs = 1;opts.batchsize = 100;nn = nntrain(nn, train_x, train_y, opts);[er, bad] = nntest(nn, test_x, test_y);assert(er < 0.16, 'Too big error');```Example: Convolutional Neural Nets---------------------```matlabfunction test_example_CNNload mnist_uint8;train_x = double(reshape(train_x',28,28,60000))/255;test_x = double(reshape(test_x',28,28,10000))/255;train_y = double(train_y');test_y = double(test_y');%% ex1 Train a 6c-2s-12c-2s Convolutional neural network %will run 1 epoch in about 200 second and get around 11% error. %With 100 epochs you'll get around 1.2% errorrand('state',0)cnn.layers = { struct('type', 'i') %input layer struct('type', 'c', 'outputmaps', 6, 'kernelsize', 5) %convolution layer struct('type', 's', 'scale', 2) %sub sampling layer struct('type', 'c', 'outputmaps', 12, 'kernelsize', 5) %convolution layer struct('type', 's', 'scale', 2) %subsampling layer};cnn = cnnsetup(cnn, train_x, train_y);opts.alpha = 1;opts.batchsize = 50;opts.numepochs = 1;cnn = cnntrain(cnn, train_x, train_y, opts);[er, bad] = cnntest(cnn, test_x, test_y);%plot mean squared errorfigure; plot(cnn.rL);assert(er<0.12, 'Too big error');```Example: Neural Networks---------------------```matlabfunction test_example_NNload mnist_uint8;train_x = double(train_x) / 255;test_x = double(test_x) / 255;train_y = double(train_y);test_y = double(test_y);% normalize[train_x, mu, sigma] = zscore(train_x);test_x = normalize(test_x, mu, sigma);%% ex1 vanilla neural netrand('state',0)nn = nnsetup([784 100 10]);opts.numepochs = 1; % Number of full sweeps through dataopts.batchsize = 100; % Take a mean gradient step over this many samples[nn, L] = nntrain(nn, train_x, train_y, opts);[er, bad] = nntest(nn, test_x, test_y);assert(er < 0.08, 'Too big error');%% ex2 neural net with L2 weight decayrand('state',0)nn = nnsetup([784 100 10]);nn.weightPenaltyL2 = 1e-4; % L2 weight decayopts.numepochs = 1; % Number of full sweeps through dataopts.batchsize = 100; % Take a mean gradient step over this many samplesnn = nntrain(nn, train_x, train_y, opts);[er, bad] = nntest(nn, test_x, test_y);assert(er < 0.1, 'Too big error');%% ex3 neural net with dropoutrand('state',0)nn = nnsetup([784 100 10]);nn.dropoutFraction = 0.5; % Dropout fraction opts.numepochs = 1; % Number of full sweeps through dataopts.batchsize = 100; % Take a mean gradient step over this many samplesnn = nntrain(nn, train_x, train_y, opts);[er, bad] = nntest(nn, test_x, test_y);assert(er < 0.1, 'Too big error');%% ex4 neural net with sigmoid activation functionrand('state',0)nn = nnsetup([784 100 10]);nn.activation_function = 'sigm'; % Sigmoid activation functionnn.learningRate = 1; % Sigm require a lower learning rateopts.numepochs = 1; % Number of full sweeps through dataopts.batchsize = 100; % Take a mean gradient step over this many samplesnn = nntrain(nn, train_x, train_y, opts);[er, bad] = nntest(nn, test_x, test_y);assert(er < 0.1, 'Too big error');%% ex5 plotting functionalityrand('state',0)nn = nnsetup([784 20 10]);opts.numepochs = 5; % Number of full sweeps through datann.output = 'softmax'; % use softmax outputopts.batchsize = 1000; % Take a mean gradient step over this many samplesopts.plot = 1; % enable plottingnn = nntrain(nn, train_x, train_y, opts);[er, bad] = nntest(nn, test_x, test_y);assert(er < 0.1, 'Too big error');%% ex6 neural net with sigmoid activation and plotting of validation and training error% split training data into training and validation datavx = train_x(1:10000,:);tx = train_x(10001:end,:);vy = train_y(1:10000,:);ty = train_y(10001:end,:);rand('state',0)nn = nnsetup([784 20 10]); nn.output = 'softmax'; % use softmax outputopts.numepochs = 5; % Number of full sweeps through dataopts.batchsize = 1000; % Take a mean gradient step over this many samplesopts.plot = 1; % enable plottingnn = nntrain(nn, tx, ty, opts, vx, vy); % nntrain takes validation set as last two arguments (optionally)[er, bad] = nntest(nn, test_x, test_y);assert(er < 0.1, 'Too big error');```[![Bitdeli Badge](https://d2weczhvl823v0.cloudfront.net/rasmusbergpalm/deeplearntoolbox/trend.png)](https://bitdeli.com/free "Bitdeli Badge")

老版QQ原生表情gif动态

这是老版的QQ表情,不过全是动态的的,Windows照片查看器是不会动的,可以右击用浏览器打开查看,再说一遍是老版的,只是分享给宁愿用老版也要动态的人。

nginx proxy_cache配置缓存

一、现在讨论两种缓存: 1、浏览器级别的缓存,通过nginx的expires 2h设置浏览器缓存文件2个小时,刷新的时候,浏览器获取该文件通过from cache获取 2、nginx通过proxy_cache缓存源服务器的静态文件,配置如下: 1)、http级别: proxy_temp_path /home/temp_dir; proxy_cache_path /home/cache

ppt0501的专栏 3265

jdk-8u144-linux-x64.tar.gz.

该资源为搭建Linux系统Java环境用,资源的后缀为tar.gz格式的压缩包

上一篇: nginx 限制并发连接数 limit_zone one
下一篇: 用lua扩展你的Nginx
大树叶
博客等级 码龄12年 1171粉丝 664原创
评论
成就一亿技术人!
拼手气红包6.0元
还能输入1000个字符
 
 条评论被折叠 查看
添加红包

请填写红包祝福语或标题

个

红包个数最小为10个

元

红包金额最低5元

当前余额3.43元 前往充值 >
需支付:10.00元
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付元
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值