美文网首页
Nginx 通过 mime type 文件类型来缓存图片

Nginx 通过 mime type 文件类型来缓存图片

作者: awker | 来源:发表于2019-11-06 23:38 被阅读0次

nginx 配置如下

map $sent_http_content_type $expires {
    default                    off;
    ~image/                    1d;
}

server {
    listen 80;
    server_name xxx.xxx.com;
    access_log logs/access.log  main;
    expires $expires;
    location  / {
        proxy_pass http://10.0.0.1:25022/media/;
    }
}

原理如下

  • The default value is set to off, which will not add any caching control headers. It’s a safe bet for content we have no particular requirements on how the cache should work.
  • The last setting is for ~image/, which is a regular expression that will match all file types containing image/ in their MIME type name (like image/jpg and image/png). Like stylesheets, there are often a lot of images on websites that can be safely cached, so we set this to max as well.

参考链接:

  1. http://nginx.org/en/docs/http/ngx_http_headers_module.html
  2. https://www.digitalocean.com/community/tutorials/how-to-implement-browser-caching-with-nginx-s-header-module-on-ubuntu-16-04
  3. https://developer.mozilla.org/zh-CN/docs/Web/HTTP/Basics_of_HTTP/MIME_types

相关文章

网友评论

      本文标题:Nginx 通过 mime type 文件类型来缓存图片

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