To optimize the site used the storage of images in the additional format .webp . The point is this: the user requests a picture image.jpg (in the browser), the web server looks, if there is such a picture in the .webp format and the browser supports, then it gives it. Used solution on .htaccess :

https://github.com/vincentorback/WebP-images-with-htaccess

And everything works fine, but on the local, I only have Apache (xampp), but there is a problem with the production server, there is a bunch of Apache and nGinx on the dedicated server, the solution does not work through .htaccess , I don’t understand the servers much, but So I understand that the site’s static is given by nGinx , and hence the question: How can I configure nGinx so that the image substitution on .webp as I wrote above?

  • Find out if you can edit Nginx configs and configure them accordingly. - Alexander Semikashev
  • You can also pay attention to my answer, which gave earlier: ru.stackoverflow.com/a/915298/237223 - Alexander Semikashev February

1 answer 1

Not sure, but here in this article suggest creating a webp.conf add the variable http_accept with the parameter webp_extension

 map $http_accept $webp_extension { default ""; "~*webp" ".webp"; } 

and rule

 location ~* ^/webp/.+\.(png|jpe?g)$ { expires 30d; add_header Vary "Accept-Encoding"; add_header Cache-Control "public, no-transform"; try_files $uri$webp_extension $uri =404; }