Make a /etc/nginx/snippet/webp-map.conf
add the following:
map $http_accept $webp_suffix {
default “”;
“~*webp” “.webp”;
}
add
include /etc/nginx/snippets/webp-map.conf;
to /etc/nginx/nginx.conf
create new nginx template just copy the one you want to use for wp, and for other sites just copy the template for that site so they don’t get overwritten in updates. add:
location ~* ^.+.(jpeg|png|jpg) {
try_files $uri$webp_suffix $uri =404;
}
add it above the first location the position matters for some reason. also add a vary header