# Image\_filter on error\_page location

**URL:** <https://www.ruby-forum.com/t/image-filter-on-error-page-location/215414>\
**Category:** NGINX\
**Created:** [January 3, 2012, 6:19pm UTC](https://www.ruby-forum.com/t/image-filter-on-error-page-location/215414 "2012-01-03T18:19:22Z")\
**Posts on this page:** 3\
**Page:** 1

<div class="post-metadata">

**Author:** ![luislavena](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/l/0ea827/32.png) [@luislavena](https://www.ruby-forum.com/u/luislavena)\
**Post date:** [January 3, 2012, 6:19pm UTC](https://www.ruby-forum.com/t/image-filter-on-error-page-location/215414/1 "2012-01-03T18:19:22Z")

</div>

Hello,  
I can’t figure how to solve such issue - nginx seems not to apply  
image\_filter in case the picture comes from upstream via internal  
error\_page.

I have something like (if picture is prefixed with sm\_ a dynamic  
thumbnail is made and the original saved locally):

location ~ /sm\_ {  
rewrite (._)/sm\_(._) $1/$2 break;  
image\_filter crop 100 100;  
error\_page 404 = @store;  
}

location @store {  
internal;  
proxy\_pass [http://backend/$uri](http://backend/$uri);  
proxy\_store on;

}

If the file doesn’t exist on the server client gets the original/full  
sized image, on the second request when the file is stored on  
the nginx box the image/response gets resized.

Also requesting directly from the upstream within the location block:

location ~ /sm\_ {  
rewrite (._)/sm\_(._) $1/$2 break;  
image\_filter crop 100 100;  
proxy\_pass [http://backend/$uri](http://backend/$uri);  
}

works as expected but in this case obviously no local copy (which is  
necessary) is made.

Any suggestions?

wbr  
rr

---

<div class="post-metadata">

**Author:** ![Reinis\_R](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/r/47e85d/32.png) [@Reinis\_R](https://www.ruby-forum.com/u/Reinis_R)\
**Post date:** [January 3, 2012, 11:08pm UTC](https://www.ruby-forum.com/t/image-filter-on-error-page-location/215414/2 "2012-01-03T23:08:30Z")

</div>

Hello!

On Tue, Jan 03, 2012 at 07:18:45PM +0200, Reinis R. wrote:

> ```
> image_filter crop 100 100;
> 
> ```
> 
> If the file doesn’t exist on the server client gets the  
> original/full sized image, on the second request when the file is  
> stored on the nginx box the image/response gets resized.

This is expected behaviour: you have no image\_filter configured in  
location @store, which handles the request if file doesn’t exists.

Obvious fix is to add image\_filter to location @store, i.e.

```
location @store {
    internal;
    proxy_pass http://backend/$uri;
    proxy_store on;
    image_filter crop 100 100;
}

```

Maxim D.

---

<div class="post-metadata">

**Author:** ![Reinis\_R](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/r/47e85d/32.png) [@Reinis\_R](https://www.ruby-forum.com/u/Reinis_R)\
**Post date:** [January 4, 2012, 2:27am UTC](https://www.ruby-forum.com/t/image-filter-on-error-page-location/215414/3 "2012-01-04T02:27:33Z")

</div>

> This is expected behaviour: you have no image\_filter configured in  
> location @store, which handles the request if file doesn’t exists.  
> Obvious fix is to add image\_filter to location @store, i.e.

I see.  
Got a feeling that will have to define a seperate 404 location for each  
thumbnail block (since there are bunch and all have different  
image\_filter  
params).

rr
