Forum: NGINX cache static content in memory

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.
nfn (Guest)
on 2009-05-28 21:04
(Received via mailing list)
Hi,

I'm using nginx with apache2 + mod_php.
Php pages are proxied to apache and nginx handles all static files (css,
js, png, jpg, gif).
I have lots of small files (forum design + smilies) ...

Can nginx cache theses files in memory? How?
If so, do I have any benefit with this approach?
Is this faster than serving from disk?

Thanks

N

Posted at Nginx Forum:
http://forum.nginx.org/read.php?2,2465,2465#msg-2465
Jérôme Loyet (Guest)
on 2009-05-28 21:46
(Received via mailing list)
Hi,

your system has already a file cache memory. It does the trick.
If you want to use nginx cache capabilities, you can make nginx
reverse proxies all requests to apache (even static ones) and set up a
cache (proxy_cache* directives). But ningx will put cached files on
disk et read them on demand. It will benefits of system cache as well.

I asked myself the same question weeks ago but in my case static files
were not on a local disk but on a NFS shared disk. So I let apache to
serve statiques pages as well and cache them localy.

Hope it helps

2009/5/28 nfn <nginx-forum@nginx.us>:
Cliff Wells (Guest)
on 2009-05-28 23:39
(Received via mailing list)
On Thu, 2009-05-28 at 14:54 -0400, nfn wrote:
> Hi,
>
> I'm using nginx with apache2 + mod_php.
> Php pages are proxied to apache and nginx handles all static files (css, js, png, jpg, 
gif).
> I have lots of small files (forum design + smilies) ...
>
> Can nginx cache theses files in memory? How?
> If so, do I have any benefit with this approach?
> Is this faster than serving from disk?

You should read this:

http://varnish.projects.linpro.no/wiki/ArchitectNotes

It offers a good explanation of why trying to cache files in memory
(beyond what the OS already does) is usually counterproductive.

Cliff
nfn (Guest)
on 2009-05-29 18:59
(Received via mailing list)
Thank you for your explanations.

Now, using proxy_cache_* am I able to cache only some pages?

Example:
site.com/
site.com/products/
site.com/products/cars/
site.com/products/cars/ferrari.php :)

How can I cache only "site.com/" and "site.com/products/"?

Thanks

N

Posted at Nginx Forum:
http://forum.nginx.org/read.php?2,2465,2476#msg-2476
Igor Sysoev (Guest)
on 2009-05-29 19:31
(Received via mailing list)
On Fri, May 29, 2009 at 12:47:03PM -0400, nfn wrote:

> How can I cache only "site.com/" and "site.com/products/"?
location / {
    proxy_cache  zone;
    ...
}

location /products/ {
    proxy_cache  zone;
    ...
}

location /products/cars/ {
    proxy_cache  off;   # default
    ...
}
nfn (Guest)
on 2009-05-29 20:14
(Received via mailing list)
Ok ..

Thanks Igor :)

So, If I have a "site.com/contact/" it will be cached since we have:

location / {
proxy_cache zone;
...
}

To avoid this I need to add:

location /contact/ {
proxy_cache off; # default
...
}

Is that it?

Posted at Nginx Forum:
http://forum.nginx.org/read.php?2,2465,2478#msg-2478
Igor Sysoev (Guest)
on 2009-05-29 20:50
(Received via mailing list)
On Fri, May 29, 2009 at 02:06:28PM -0400, nfn wrote:

>
> To avoid this I need to add:
>
> location /contact/ {
> proxy_cache off; # default
> ...
> }
>
> Is that it?

If you set

location / {
    proxy_cache zone;
    ...
}

location /contact/ {
    ...
}

then /contact wil not be cached.
nfn (Guest)
on 2009-05-29 22:21
(Received via mailing list)
Thank you Igor,

Maybe a suggestion (I don't know nginx fully) ... have a regular
expression implementation to cache functions.

Thanks

N

Posted at Nginx Forum:
http://forum.nginx.org/read.php?2,2465,2488#msg-2488
Igor Sysoev (Guest)
on 2009-05-30 09:07
(Received via mailing list)
On Fri, May 29, 2009 at 04:05:58PM -0400, nfn wrote:

> Thank you Igor,
>
> Maybe a suggestion (I don't know nginx fully) ... have a regular expression 
implementation to cache functions.

http://wiki.nginx.org/NginxHttpCoreModule#location
nfn (Guest)
on 2009-05-30 15:56
(Received via mailing list)
Thank you Igor. I already know that.

I was think about something like this just to proxy_cache &
fastcgi_cache:

location / {
  proxy_cache zone;
  ...
  proxy_match ^~ /products/;
  proxy_match ^~ /catalog/;
  ...
}

Posted at Nginx Forum:
http://forum.nginx.org/read.php?2,2465,2505#msg-2505
Igor Sysoev (Guest)
on 2009-05-30 21:37
(Received via mailing list)
On Sat, May 30, 2009 at 09:48:01AM -0400, nfn wrote:

> }
I do not understand semantics of this.
budala10 (Guest)
on 2010-02-22 23:12
(Received via mailing list)
What does the proxy cache?

Cache php files with queries or only static data.

I need a php cace does this do that?

example php?id=2&r=tr

the output from the php do i want to cache so the backend don't get a
request before the cache is cleared.


how, with proxy cache or proxy store ?

Posted at Nginx Forum:
http://forum.nginx.org/read.php?2,2465,56276#msg-56276
Almir Karic (Guest)
on 2010-02-23 03:39
(Received via mailing list)
linux and many other unix flavors have decent file system buffers
which make sure that the disk access is cached if enough free ram is
available.

If you want to force the cached static stuff you can mount it on tmpfs
(or alternative of your OS)


On Mon, Feb 22, 2010 at 2:12 PM, budala10 <nginx-forum@nginx.us> wrote:
>
> how, with proxy cache or proxy store ?
>
> Posted at Nginx Forum: http://forum.nginx.org/read.php?2,2465,56276#msg-56276
>
>
> _______________________________________________
> nginx mailing list
> nginx@nginx.org
> http://nginx.org/mailman/listinfo/nginx
>



--
python/django hacker & sys admin
http://almirkaric.com & http://twitter.com/redduck666
Ryan Malayter (Guest)
on 2010-02-24 06:07
(Received via mailing list)
On Mon, Feb 22, 2010 at 4:12 PM, budala10 <nginx-forum@nginx.us> wrote:
> What does the proxy cache?
> Cache php files with queries or only static data.
> I need a php cace does this do that?
> example php?id=2&r=tr
> the output from the php do i want to cache so the backend don't get a request before the 
cache is cleared.
> how, with proxy cache or proxy store ?

You want to use proxy_cache in nginx, but you should set appropriate
Cache-Control headers in your PHP scripts so that nginx will obey
them.

Typically, to cache the output of a PHP script in a proxy like nginx,
you would want something like "Cache-Control: public,max-age=3600"

Most PHP implementations set "Cache-Control: private" or
"Cache-Control: no-cache" by default for all pages, which you need to
override.

--
RPM
This topic is locked and can not be replied to.