Forum: NGINX Fastcgi cache

Announcement (2017-05-07): www.ruby-forum.com is now read-only since I unfortunately do not have the time to support and maintain the forum any more. Please see rubyonrails.org/community and ruby-lang.org/en/community for other Rails- und Ruby-related community platforms.
2974d09ac2541e892966b762aad84943?d=identicon&s=25 Jim Ohlstein (Guest)
on 2009-05-09 21:14
(Received via mailing list)
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:
http://forum.nginx.org/read.php?2,1890,1890#msg-1890
2974d09ac2541e892966b762aad84943?d=identicon&s=25 "坏人" (Guest)
on 2009-05-12 06:06
(Received via mailing list)
如果是js、css、gif等推荐用squid。如果是大的媒体文件,推荐用rsync同步后再用ngninx输出。

Posted at Nginx Forum:
http://forum.nginx.org/read.php?2,1890,1925#msg-1925
5640e332954fc0006aea97a155ce0afd?d=identicon&s=25 Igor Sysoev (Guest)
on 2009-05-12 08:44
(Received via mailing list)
On Sat, May 09, 2009 at 03:02:53PM -0400, Jim Ohlstein 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.
6d4a6e9574c15d11480db6d7e5eb2750?d=identicon&s=25 Delta Yeh (Guest)
on 2009-05-12 12:18
(Received via mailing list)
+1 cent for proxy  using content-type

2009/5/12 Igor Sysoev <is@rambler-co.ru>
2974d09ac2541e892966b762aad84943?d=identicon&s=25 Jim Ohlstein (Guest)
on 2009-05-13 19:51
(Received via mailing list)
Finally that worked.

Thank you Igor!

Posted at Nginx Forum:
http://forum.nginx.org/read.php?2,1890,2005#msg-2005
2974d09ac2541e892966b762aad84943?d=identicon&s=25 Jim Ohlstein (Guest)
on 2009-05-13 23:17
(Received via mailing list)
Igor Sysoev 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 Sysoev
> http://sysoev.ru/en/

Posted at Nginx Forum:
http://forum.nginx.org/read.php?2,1890,1993#msg-1993
5640e332954fc0006aea97a155ce0afd?d=identicon&s=25 Igor Sysoev (Guest)
on 2009-05-13 23:39
(Received via mailing list)
On Wed, May 13, 2009 at 12:06:33AM -0400, Jim Ohlstein 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 ...
}
2974d09ac2541e892966b762aad84943?d=identicon&s=25 Jim Ohlstein (Guest)
on 2009-05-14 10:10
(Received via mailing list)
Igor Sysoev 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 Sysoev
> http://sysoev.ru/en/

Posted at Nginx Forum:
http://forum.nginx.org/read.php?2,1890,2000#msg-2000
5640e332954fc0006aea97a155ce0afd?d=identicon&s=25 Igor Sysoev (Guest)
on 2009-05-14 10:24
(Received via mailing list)
On Wed, May 13, 2009 at 10:59:13AM -0400, Jim Ohlstein 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;
2c6f80fff253635f12c249ef4f116796?d=identicon&s=25 Jim Ohlstein (Guest)
on 2009-05-14 10:57
(Received via mailing list)
Igor Sysoev wrote:
>>>> Igor Sysoev 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
5640e332954fc0006aea97a155ce0afd?d=identicon&s=25 Igor Sysoev (Guest)
on 2009-05-14 11:08
(Received via mailing list)
On Wed, May 13, 2009 at 11:42:25AM -0400, Jim Ohlstein 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.
2974d09ac2541e892966b762aad84943?d=identicon&s=25 Jim Ohlstein (Guest)
on 2009-05-19 23:18
(Received via mailing list)
Is there a way to log cache hits and misses?

Posted at Nginx Forum:
http://forum.nginx.org/read.php?2,1890,2207#msg-2207
A8108a0961c6087c43cda32c8616dcba?d=identicon&s=25 Maxim Dounin (Guest)
on 2009-05-19 23:40
(Received via mailing list)
Hello!

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

> Is there a way to log cache hits and misses?

Not yet.

Maxim Dounin
2c6f80fff253635f12c249ef4f116796?d=identicon&s=25 Jim Ohlstein (Guest)
on 2009-05-19 23:54
(Received via mailing list)
Maxim Dounin wrote:
> Hello!
>
> On Tue, May 19, 2009 at 05:09:39PM -0400, Jim Ohlstein wrote:
>
>
>> Is there a way to log cache hits and misses?
>>
>
> Not yet.
>

Thanks Maxim. I can live with the word "yet".  :)
> Maxim Dounin
>
>
>
Jim
D0a98f6304ff122ac9b487ff8275d8bb?d=identicon&s=25 Payam Chychi (Guest)
on 2009-05-20 07:41
(Received via mailing list)
On Tue, May 19, 2009 at 2:49 PM, Jim Ohlstein <jim.ohlstein@gmail.com>
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...
This topic is locked and can not be replied to.