Image_filter before proxy_store


#1

Hello,
wanted a suggestion on such setup - the idea is to create on-the-fly
image resizing and storing the thumbnails on the disk (kinda at
some level on-demand mirror with file altering and storing them in the
same tree as parent host (rather than using
proxy_cache_path)).

The basic setup:

server {
root /data;

location ~* (.*)/small_(.*) {
         error_page      404 = @small;
 }

location @small {
            internal;
            image_filter   resize  100 100;
            proxy_pass           http://imgstore$1/$2;
            proxy_store          on;
    }

}

The idea is - if a request http://server/small_picture.jpg is made and
the file doesnt exist on local storage is is passed to a
parent image store server which holds only ‘picture.jpg’, resized and
stored locally…

The issue is that the ‘small_picture.jpg’ (actually the large version)
is now saved before the image_filter kicks in and client
gets the thumbnail only on first request.

I could of course change the proxy_pass to make a request back to for
example http://127.0.0.1/small/small_picture.jpg and then
define location /small {} which contains the resize and parent
proxy_pass definition, but wanted to ask maybe if there is more
optimal solution rather than making a second request to nginx itself.

wbr
rr


#2

Reinis R. wrote:

I could of course change the proxy_pass to make a request back to for
example http://127.0.0.1/small/small_picture.jpg and then define
location /small {} which contains the resize and parent proxy_pass
definition, but wanted to ask maybe if there is more optimal solution
rather than making a second request to nginx itself.

Better to use separate nginx instance for resizing, and proxy_cahce with
proxy_pass to resizer
in main instance.

Resize can block on CPU for relatively long time.