magenx / Magento-nginx-config

Default Nginx config for Magento 2
https://www.magenx.com
GNU General Public License v3.0
506 stars 211 forks source link

Magento 2 webp #36

Closed ufo56 closed 4 years ago

ufo56 commented 4 years ago

Hi

Im trying to serve webp images if they exist on /media/ folder.

My current assets.conf looks like this. I can't figure out why get.php won't be called if jpg/png picture on cache does not exist. If there is no product image on cache i get 404 to image that this does not exist, i think its because get.php does not create that.

        location /media/ { 

        ####webp####
               location ~* ^(/media/.+)\.(png|jpe?g)$ {
                 set $base $1;
                 set $webp_uri $base$webp_suffix;
                 set $webp_old_uri $base.$2$webp_suffix;
                 set $root "/vaw/www/htdocs/pub";
                 root $root;
                 expires max;
                 add_header Cache-Control "public";
                 add_header Vary Accept;
                  if ( !-f $root$webp_uri ) {
                          add_header X_WebP_SP_Miss $root$webp_uri;
                   }
                 try_files $webp_uri $webp_old_uri $uri $uri/ /get.php$is_args$args  =404;
         }
       ########

        ## images css js
        location ~* \.(jpg|jpeg|png|webp|gif|svg|js|css|ico|txt)$ {
                expires max;
                add_header Cache-Control "public";
                try_files $uri $uri/ @media;
        }

        ## fonts

        location ~* \.(swf|eot|ttf|otf|woff|woff2)$ {
                expires max;
                add_header Cache-Control "public";
                try_files $uri $uri/ @media;
        }
        try_files $uri $uri/ @media;
        }

        location @static { rewrite /static/(version\d*/)?(.*)$ /static.php?resource=$2 last; }
        location @media { try_files $uri $uri/ /get.php$is_args$args; }