常用的功能。
访问不存在的图片显示默认图片
Nginx
location ~* \.(jpg|jpeg|gif|png)$ {
try_files $uri /not-exists.jpg =404;
}
Apache
...
设置指定文件类型过期时间
Nginx
location ~* \.(jpg|gif|png|ico|gif|css|js|svg)$ {
expires 30d;
}
# 其时间单位有如下选项
# ms milliseconds
# s seconds
# m minutes
# h hours
# d days
# w weeks
# M months, 30 days
# y years, 365 days
Apache
ExpiresActive on
ExpiresByType image/jpg "access 1 years"
ExpiresByType image/png "access 1 years"
ExpiresByType image/gif "access 1 years"
ExpiresByType image/jpeg "access 1 years"
# 其时间单位有如下选项
# years
# months
# weeks
# days
# hours
# minutes
# seconds