Saturday, May 14, 2022

[FIXED] how to resize images via nginx

Issue

everybody. tell me how to solve this puzzle. Nginx passes the URL type https://example.com/thumbs/_default_upload_bucket/236/280/5804.jpeg If this image does not exist, nginx should retrieve and resize the original image: replace "thumbs/" and size "236/280/" URL will be https://example.com/_default_upload_bucket/5804.jpeg

If I understand correctly to do this through the module ngx_http_image_filter_module.

How to do this through nginx. Thanks.


Solution

after research, i created a configuration that needed to me.

location ~* /thumbs/(.*)/(\d+)/(\d+)/(.*)$ {
            set $bucket $1;
            set $width $2;
            set $height $3;
            set $filename $4;
    try_files /$1/$2/$3/$4 @images;
    root /var/www/html/tmp/image-thumbnails;
    expires 2w;
    access_log off;
}


location @images {
            root /var/www/html/assets/;
            rewrite ^.*$ /$bucket/$filename break;
            image_filter_buffer 50M;
            image_filter resize $width $height;
}


Answered By - James M
Answer Checked By - Dawn Plyler (PHPFixing Volunteer)

No comments:

Post a Comment

Note: Only a member of this blog may post a comment.