美文网首页
Nginx 缓存

Nginx 缓存

作者: YonchanLew | 来源:发表于2022-03-08 09:56 被阅读0次

浏览器缓存

location /files { 
  alias /home/imooc; 
  # expires 10s; 
  # expires @22h30m; 
  # expires -1h; 
  # expires epoch; 
  # expires off; 
  expires max; 
}

反向代理缓存

# proxy_cache_path 设置缓存目录 
# keys_zone 设置共享内存以及占用空间大小 
# max_size 设置缓存大小 
# inactive 超过此时间则被清理 
# use_temp_path 临时目录,使用后会影响nginx性能 
proxy_cache_path /usr/local/nginx/upstream_cache keys_zone=mycache:5m max_size=1g inactive=1m use_temp_path=off;

location / { 
  proxy_pass http://tomcats; 
  # 启用缓存,和keys_zone一致 
  proxy_cache mycache; 
  # 针对200和304状态码缓存时间为8小时 
  proxy_cache_valid 200 304 8h; 
}

相关文章

网友评论

      本文标题:Nginx 缓存

      本文链接:https://www.haomeiwen.com/subject/qjhbrrtx.html