Skip to content
VirtuBox edited this page Mar 24, 2018 · 3 revisions

Webp support

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://raw.githubusercontent.com/VirtuBox/nginx-ee/master/etc/nginx/conf.d/webp.conf

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;
}

With EasyEngine, you can directly add it in /etc/nginx/common/wpcommon.conf and /etc/nginx/common/wpcommon-php7.conf to enable webp support for all wordpress websites

Check if there are errors with nginx -t before reloading nginx with service nginx reload


Customizing Nginx compilation

Nginx Configuration :

Plesk Configuration :

Clone this wiki locally