test.conf

proxy_cache_path cache levels=1:2 keys_zone=my_cache:10m;

server {
listen 80;
server_name testyhl.com; location / {
proxy_cache my_cache;
proxy_pass http://127.0.0.1:8888;
proxy_set_header Host $host;
}
}

server.js

const http = require('http')
const fs = require('fs') const wait = (seconds) => {
return new Promise((resolve, reject) => {
setTimeout(() => {
resolve()
}, seconds * 1000)
})
} http.createServer((request, response) => {
console.log('requres come', request.url) if (request.url === '/') {
const html = fs.readFileSync('test.html', 'utf-8') response.writeHead(200, {
'Content-Type': 'text/html'
}) response.end(html)
} if (request.url === '/data') {
response.writeHead(200, {
'Cache-Control': 'max-age=5, s-maxage=20, private',
    'Vary': 'X-Test-Cache'
})
wait(2).then(() => response.end('success'))
} }).listen(8888) console.log('server listening on 8888')

test.html

<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="UTF-8">
<meta name="viewport" content="width=device-width, initial-scale=1.0">
<title>Document</title>
</head>
<body>
<div>This is content, and data is: <span id="data"></span></div>
</body>
<script>
fetch('/data').then((res) => {
return res.text()
}).then((text) => {
document.getElementById('data').innerText = text
})
</script>
</html>

nginx-cache的更多相关文章

  1. nginx cache的玩法

      一.简介 Nginx版本从0.7.48开始,支持了类似Squid的缓存功能.这个缓存是把URL及相关组合当做Key,用Md5算法对Key进行哈希,得到硬盘上对应的哈希目录路径,从而将缓存内容保存在 ...

  2. 查看nginx cache命中率

    一.在http header上增加命中显示 nginx提供了$upstream_cache_status这个变量来显示缓存的状态,我们可以在配置中添加一个http头来显示这一状态,达到类似squid的 ...

  3. NGINX Cache Management (.imh nginx)

    In this article, we will explore the various NGINX cache configuration options, and tips on tweaking ...

  4. FastDFS_v5.05+nginx+cache集群安装配置手册

    转载请出自出处:http://www.cnblogs.com/hd3013779515/ 1.FastDFS简单介绍 FastDFS是由淘宝的余庆先生所开发,是一个轻量级.高性能的开源分布式文件系统, ...

  5. 使用nginx cache缓存网站数据实践

    Nginx本身就有缓存功能,能够缓存静态对象,比如图片.CSS.JS等内容直接缓存到本地,下次访问相同对象时,直接从缓存即可,无需访问后端静态服务器以及存储存储服务器,可以替代squid功能. 1   ...

  6. Nginx Cache中$request_filename(转)

    对于Nginx的$request_filename变量指的就是请求的资源路径.在原先 OpenCDN节点端配置里面是这样的. location ~ .*\.(png|html|htm|ico|jpg| ...

  7. varnish/squid/nginx cache 有什么不同?

    SQUID 是功能最全面的,但是架构太老,性能不咋的Varnish 是内存缓存,速度一流,但是内存缓存也限制了其容量,缓存页面和图片一般是挺好的Nginx 本来是反向代理/web服务器,用了插件可以做 ...

  8. web cache server方案比较:varnish、squid、nginx

    linux运维中,web cache server方案的部署是一个很重要的环节,选择也有很多种比如:varnish.squid.nginx.下面就对当下常用的这几个web cache server做一 ...

  9. 死磕nginx系列--使用nginx做cache服务

    配置文件 nginx.conf 主配置文件 worker_processes 1; events { worker_connections 1024; } http { include mime.ty ...

  10. [svc]tomcat目录结构/虚拟主机/nginx反向代理cache配置

    tomcat目录文件 /usr/local/tomcat/bin/catalina.sh stop sleep 3 /usr/local/tomcat/bin/catalina.sh start to ...

随机推荐

  1. Java第一个程序HelloWorld

    1.创建一个java源文件:HelloWorld.java public class HelloWorld{ public static void main(String[] args){ Syste ...

  2. HTML的页面结构

    HTML的页面结构 以下为命名的规范: header:标题头部区域的内容(用于页面或页面中的一块区域) footer:标记脚步区域的内容(用于整个页面或页面的一块区域) nav:导航类复杂内容 以上3 ...

  3. List数组排序

    import java.util.ArrayList; import java.util.Collections; import java.util.Comparator; import java.u ...

  4. 钉钉内网穿透工具在windows的使用。

    钉钉内网穿透工具在windows环境下使用 1.WIN+R,然后cmd,调出dos控制台 2.进入内网穿透程序ding.exe所在目录 3.执行 ./ding.exe -config=ding.cfg ...

  5. Ubuntu安装程序报错:无法获得锁 /var/lib/dpkg/lock-frontend - open (11: 资源暂时不可用)

    问题描述:在使用Ubuntu系统时安装程序时出现下面的报错. E: 无法获得锁 /var/lib/dpkg/lock-frontend - open (11: 资源暂时不可用)E: Unable to ...

  6. Oracle的表空间、用户和表的区别和联系

    Oracle的表空间.用户和表的区别和联系 Oracle数据库是通过表空间来存储实际存在的那些表.索引.视图的, 表空间分类: 临时表空间:   用于存储数据库中单持久性模型对象,如表.索引.视图等, ...

  7. springmvc、 springboot 项目全局异常处理

    异常在项目中那是不可避免的,通常情况下,我们需要对全局异常进行处理,下面介绍两种比较常用的情况. 准备工作: 在捕获到异常的时候,我们通常需要返回给前端错误码,错误信息等,所以我们需要手动封装一个js ...

  8. 【转载】Win7下如何使用GCC编译器

    转自:http://jingyan.baidu.com/article/c275f6bacc0126e33c756771.html 双击GCC安装包,mingw-get-setup.exe,点击Ins ...

  9. 解决async 运行多线程时报错RuntimeError: There is no current event loop in thread 'Thread-2'

    原来使用: loop = asyncio.get_event_loop()task = asyncio.ensure_future(do_work(checker))loop.run_until_co ...

  10. 安装mongo以及相关扩展

    背景:看到了一个nodejs的对mongo操作的课程,于是想学一下. * 1.于是打算先在自己的vps上安装一个mongodb:[ https://docs.mongodb.org/manual/tu ...