嗨,我正在尝试为Nginx wordpress网站实现Webp支持。
并遵循本指南https://www.digitalocean.com/community/tutorials/how-to-create-and-serve-webp-images-to-speed-up-your-website 要将图像转换为webp格式,我看到.webp
中所有具有重复文件的图像已添加 图像/ WebP WebP;到/etc/nginx/mime.types; 我已经添加到主要的nginx.conf
#Add this block, before the server directive.
#This mapping checks whether the browser client supports WebP images,
#when it does it will set WebP image files as default source.
map $http_accept $webp_suffix {
default "";
"~*webp" ".webp";
}
**Also added below to the sververblock**
location ~* ^(/wp-content/.+)\.(jpe?g|png) {
add_header Cache-Control "public, no-transform";
add_header Vary Accept;
try_files $1$webp_suffix $uri =404;
expires max;
}