'how to resize images via nginx
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 1:[1]
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;
}
Solution 2:[2]
Nginx provides the image_filter module for the dynamic image resizing. This Nginx configuration will allow for requests such as http://server.com/images/880/dis.jpg - this image will be resized to 880 pixels wide and compressed using the quality value of 90. Requests asking for images larger than 10 megabytes (before resizing) will be resized.
server {
listen 80 default_server;
server_name server.com;
location ~ "^/images/(?<width>\d+)/(?<image>.+)$" {
alias /srv/www/images/$image;
image_filter resize $width -;
image_filter_jpeg_quality 90;
image_filter_buffer 10M;
}
}
Sources
This article follows the attribution requirements of Stack Overflow and is licensed under CC BY-SA 3.0.
Source: Stack Overflow
| Solution | Source |
|---|---|
| Solution 1 | James M |
| Solution 2 | abderrezague mohamed |
