-
-
Notifications
You must be signed in to change notification settings - Fork 58
Webp Support
VirtuBox edited this page Aug 22, 2019
·
3 revisions
To support Webp with Nginx, and display automatically webp images with compatible web browser, it require to use the map directive in the global nginx configuration with a location directive in each vhost.
Map directive to add in /etc/nginx/conf.d
is :
map $http_accept $webp_suffix {
default "";
"~*webp" ".webp";
}
You can download it directly with the following command :
wget -O /etc/nginx/conf.d/webp.conf https://git.io/fjNf2
Then, you have to add the following configuration in each nginx vhosts.
location ~* ^/wp-content/.+\.(png|jpg)$ {
add_header Vary Accept;
add_header "Access-Control-Allow-Origin" "*";
access_log off;
log_not_found off;
expires max;
try_files $uri$webp_suffix $uri =404;
}
Check if there are errors with nginx -t
before reloading nginx with service nginx reload