NGINX as proxy before apache, and localy store php generated images

Hello everyone,

I am using nginx as proxy before apache a long time already. And it is
really terrific what it does.
Ram usage dropped like 3 times
I mainly set up image cache headers in nginx config

Today I’ve spotted, that one of vhosts is generating images ALWAYS on
the
fly, images are accessed like:
/bin/825?w=121&h=87&cutted=fit
/bin/4999?w=222
/bin/5113?w=121&h=87&cutted=fit

etc…

I wonder is there any way I can tell nginx to store those images
locally,
ie for a week, and serve them
to other users, so it won’t be resized multiple times?

I tried googling but don’t even know how/where to start from…

Thank you in advance!
huglester

Thank you very much Igor for a fast response!

So far I see the performance increase. I see the logs being created. And
no
longer see so lot access logs to apache images.

my config is:
location /bin/ {
expires 7d;
add_header X-Cache “Backend2-cache”;
proxy_pass http://site.com;

            proxy_cache my-cache;
            proxy_cache_valid  200 302  360m;
            proxy_cache_valid  404      1m;
        }

One more question is left in my mind, I see the expire headers are set,
but
the HTTP response status is always 200.
is there somewhere a way to make it respond with status 304 (not
modified)
?

Thank you

On Sep 28, 2012, at 12:10 , Jaroslav wrote:

etc…

I wonder is there any way I can tell nginx to store those images locally, ie for
a week, and serve them
to other users, so it won’t be resized multiple times?

I tried googling but don’t even know how/where to start from…

http://nginx.org/en/docs/http/ngx_http_proxy_module.html#proxy_cache

On Sep 28, 2012, at 13:15 , Jaroslav wrote:

            proxy_cache my-cache;
            proxy_cache_valid  200 302  360m;
            proxy_cache_valid  404      1m;
        }

One more question is left in my mind, I see the expire headers are set, but the
HTTP response status is always 200.
is there somewhere a way to make it respond with status 304 (not modified) ?

Do these images have “Last-Modified” or “ETag” header field ?


Igor S.

I am afraid they not :frowning:

Those images by default are expiring in epoch.
You want to say than nginx will handle this 304 thing if those headers
are
correctly set in PHP?

Can this be ‘fixed’ without touching php code?

Thank you

On Sep 28, 2012, at 13:31 , Jaroslav wrote:

I am afraid they not :frowning:

Those images by default are expiring in epoch.
You want to say than nginx will handle this 304 thing if those headers are
correctly set in PHP?

Not nginx but browsers: they do not send If-Modified-Since/If-None-Match
header fields to nginx.
If these images never expire then you can add

location /bin/ {
expires 7d;
add_header ETag ‘“anything”’;


Igor S.