nginx 发送动态内容注意事项

静态文件优化

对于静态文件,如图片、文档、视频,应尽量设置较大的缓存时间。
如:

location ~ \.(gif|jpg|jpeg|png|bmp|ico)$ {
           root /var/www/img/;
           expires 30d;
       }

动态文件优化

对于动态文件,要根据文件更新的频率来设置缓存时间。

location  /dyna/ {
     root  /var/pub/;

         #避免出现发送错误的文件大小,消除 pread() read only 错误
     open_file_cache off;
     #3秒
         expires 3s;

         #告诉浏览器及时更新
     add_header Cache-Control no-cache;
     add_header Pragma no-cache;
     add_header Expires 3;
}
發表評論
所有評論
還沒有人評論,想成為第一個評論的人麼? 請在上方評論欄輸入並且點擊發布.
相關文章