缓存配置proxy_cache.conf:
#设置Web缓存区名称为cache,内存缓存空间大小为500MB #1天没有被访问的内容自动清除,硬盘缓存空间大小为50GB #levels=1:2 表示缓存目录的第一级目录是1个字符,第二级目录是2个字符 #proxy_cache_key 设置缓存的key,以域名、URI、参数组合成Web缓存的Key值,Nginx根据Key值哈希,存储缓存内容到二级缓存目录内 proxy_cache_path /home/cache levels=1:2 keys_zone=cache:500m inactive=1d max_size=50g; proxy_cache_valid 200 304 301 302 8h; proxy_cache_valid 404 1m; proxy_cache_key $host$uri$is_args$args;
domain.conf:
server { listen 80; server_name domain.test.com; access_log /usr/local/nginx/logs/domain.test.com.access.log access; location ~ .*\.(gif|jpg|jpeg|png|bmp|swf|css|js|ico)?$ { expires 1d;#缓存时间 proxy_cache cache;#设置资源缓存的zon add_header Nginx-Cache "$upstream_cache_status";#显示缓存的状态 proxy_pass http://domain; } location / { proxy_pass http://domain; } error_page 500 502 503 504 /50x.html; location = /50x.html { root html; } } upstream report { fair; server 172.16.0.10:8882 weight=1 max_fails=2 fail_timeout=30s; server 172.16.0.10:8881 weight=1 max_fails=2 fail_timeout=30s; }
重启Nginx,清空浏览器缓存,刷新页面,F12 查看:
Cache-Control:max-age=86400 Connection:keep-alive Content-Encoding:gzip Content-Type:application/javascript Date:Fri, 05 May 2019 08:21:22 GMT Expires:Sat, 06 May 2019 08:21:22 GMT Last-Modified:Thu, 27 Apr 2019 01:27:36 GMT Nginx-Cache:HIT Server:Tengine/2.1.1 Transfer-Encoding:chunked
关注
感谢阅读,如果这篇文章帮助了您,欢迎 点赞 ,收藏,关注,转发 哟。您的帮助是我们前行的动力,我们会提供更多有价值的内容给大家... 谢谢!
本文暂时没有评论,来添加一个吧(●'◡'●)