1
0
Fork 0
mirror of https://github.com/VirtuBox/nginx-ee.git synced 2026-04-27 03:15:49 +03:00
3 Webp Support
VirtuBox edited this page 2019-08-22 10:57:28 +02:00

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://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