This is how you can easily make Nginx serving webp images if disponible & if browser support it.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| http { | |
| ## | |
| # WebP conf | |
| ## | |
| map $http_accept $webp_suffix { | |
| default ""; | |
| "~*webp" ".webp"; | |
| } | |
| ## | |
| # Minimal server | |
| ## | |
| server { | |
| […] | |
| location ~* ^/images/.+\.(png|jpe?g)$ { | |
| root /home/www-data; | |
| add_header Vary Accept; | |
| try_files $uri$webp_suffix $uri =404; | |
| } | |
| } | |
| } |