Nginx配置浏览器缓存

通过expires指令,将指定后缀的请求设置缓存。

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
upstream localblog {
server 192.168.0.108:4000;
}


server {
listen 80;
server_name 192.168.0.108;
client_max_body_size 1000M;
sendfile on;

location / {
#root /opt/dist;
proxy_pass http://localblog;
index index.html;

if ($request_filename ~* ^.*?\.(ico|jpg|jpeg|gif|png|woff|woff2|bmp|js|css)$) {
expires 1d;
}
}
}

可参考知识点

  • Last-Modified/If-Modified-Since
  • Etag/If-None-Match
  • Cache-Control: max-age和expires
  • Expires

Nginx配置浏览器缓存
http://www.tung7.com/实践出真知/Nginx配置浏览器缓存.html
Author
Tung7
Posted on
September 3, 2016
Licensed under