Fastcgi cache

Igor,

Is there any way to set the it just to cache image and other media
files, but not text/html? I only see based on response in the Russian
docs (best as I can understand). Is that something that can be added or
is planned?

Posted at Nginx Forum:

如果是js、css、gif等推荐用squid。如果是大的媒体文件,推荐用rsync同步后再用ngninx输出。

Posted at Nginx Forum:

+1 cent for proxy using content-type

2009/5/12 Igor S. [email protected]

On Sat, May 09, 2009 at 03:02:53PM -0400, Jim O. wrote:

Is there any way to set the it just to cache image and other media files, but not text/html? I only see based on response in the Russian docs (best as I can understand). Is that something that can be added or is planned?

No, currently nginx can not cache using content-type, but it can be easy
added. Also you may use location to separate responses.

Igor S. Wrote:

content-type, but it can be easy
added. Also you may use location to separate
responses.

Can you give a sample configuration of how that would work.

I have tried putting location blocks in and out of the main fastcgi_pass
block without any success.


Igor S.
Igor Sysoev

Posted at Nginx Forum:

On Wed, May 13, 2009 at 12:06:33AM -0400, Jim O. wrote:

No, currently nginx can not cache using
content-type, but it can be easy
added. Also you may use location to separate
responses.

Can you give a sample configuration of how that would work.

I have tried putting location blocks in and out of the main fastcgi_pass block without any success.

location ~ .php$ {
fastcgi_pass …
}

location ~ .(jpg|gif|png)$ {
fastcgi_pass …
fastcgi_cache …
}

Finally that worked.

Thank you Igor!

Posted at Nginx Forum:

Igor S. Wrote:

Is there any way to set the it just to
content-type, but it can be easy

location ~ .php$ {
fastcgi_pass …
}

location ~ .(jpg|gif|png)$ {
fastcgi_pass …
fastcgi_cache …
}

That’s what I tried first: It’s a Perl script and I am using fcgiwrap.

location ~ myscript {
fastcgi_pass unix:/tmp/cgi.sock;
include /usr/local/nginx/conf/fastcgi_params;
fastcgi_buffers 64 8k;
}

location ~ .(jpg|gif|png)$ {
fastcgi_pass unix:/tmp/cgi.sock;
fastcgi_cache one;
fastcgi_cache_key unix:/tmp/cgi.sock.1$request_uri;
fastcgi_cache_valid 200 302 5m;
fastcgi_cache_valid 301 1d;
fastcgi_cache_valid any 5m;
include /usr/local/nginx/conf/fastcgi_params;
fastcgi_buffers 64 8k;
}

The only thing that winds up in the cache is when there is a 403.


Igor S.
Igor Sysoev

Posted at Nginx Forum:

On Wed, May 13, 2009 at 10:59:13AM -0400, Jim O. wrote:

Ohlstein wrote:

of the main fastcgi_pass block without any

location ~ .(jpg|gif|png)$ {
The only thing that winds up in the cache is when there is a 403.
Probably you need to add

fastcgi_ignore_headers Cache-Control Expires;

Igor S. wrote:

Igor S. Wrote:

(best as I can understand). Is that something

 fastcgi_pass  ...

fastcgi_cache_valid 200 302 5m;

fastcgi_ignore_headers Cache-Control Expires;

That didn’t change anything.

If I configure with:

location ~ myscript {
fastcgi_pass unix:/tmp/cgi.sock;
fastcgi_cache one;
fastcgi_cache_key unix:/tmp/cgi.sock.1$request_uri;
fastcgi_cache_valid 200 302 5m;
fastcgi_cache_valid 301 1d;
fastcgi_cache_valid any 5m;
include /usr/local/nginx/conf/fastcgi_params;
fastcgi_buffers 64 4k;
}

then files wind up in the cache. So I know the cache is configured and
working.

Jim

Is there a way to log cache hits and misses?

Posted at Nginx Forum:

On Wed, May 13, 2009 at 11:42:25AM -0400, Jim O. wrote:

Ohlstein wrote:

added. Also you may use location to separate
success.

fastcgi_pass unix:/tmp/cgi.sock;

then files wind up in the cache. So I know the cache is configured and
working.

Then change the locations order:

location ~ .(jpg|gif|png)$ {
}

location ~ myscript {
}

It seems that your images have “myscript” string.

Maxim D. wrote:

Hello!

On Tue, May 19, 2009 at 05:09:39PM -0400, Jim O. wrote:

Is there a way to log cache hits and misses?

Not yet.

Thanks Maxim. I can live with the word “yet”. :slight_smile:

Maxim D.

Jim

Hello!

On Tue, May 19, 2009 at 05:09:39PM -0400, Jim O. wrote:

Is there a way to log cache hits and misses?

Not yet.

Maxim D.

On Tue, May 19, 2009 at 2:49 PM, Jim O. [email protected]
wrote:

Is there a way to log cache hits and misses?

Jim

what about parsing log file and capturing for w.e code you decide to
cache then use sort and uniq and other tools like awk to come up with
your own stats…