proxy_cache ramdisk

Igor Sysoev igor at sysoev.ru
Mon Feb 1 20:35:33 MSK 2010


On Mon, Feb 01, 2010 at 11:26:23AM -0600, AMP Admin wrote:

> -----Original Message-----
> From: Igor Sysoev [mailto:igor at sysoev.ru] 
> Sent: Monday, February 01, 2010 11:06 AM
> To: nginx at nginx.org
> Subject: Re: proxy_cache ramdisk
> 
> On Mon, Feb 01, 2010 at 10:50:37AM -0600, AMP Admin wrote:
> 
> > -----Original Message-----
> > From: Igor Sysoev [mailto:igor at sysoev.ru] 
> > Sent: Monday, February 01, 2010 10:38 AM
> > To: nginx at nginx.org
> > Subject: Re: proxy_cache ramdisk
> > 
> > On Sun, Jan 31, 2010 at 04:26:05PM -0600, AMP Admin wrote:
> > 
> > > I'm able to cache php pages with the following but I can't seem to cache
> > > static images with proxy_cache.
> > > 
> > > 
> > > This works:
> > > 
> > >         location ~ \.php$ {
> > >
> > >                         fastcgi_index index.php;
> > >                         fastcgi_pass 127.0.0.1:9000;
> > >                         fastcgi_cache cachephp;
> > >                         fastcgi_cache_key 127.0.0.1:9000$request_uri;
> > >                         fastcgi_cache_valid 200  1h;
> > >                         include fastcgi_params;
> > >                         fastcgi_intercept_errors On;
> > >                         fastcgi_ignore_client_abort On;
> > 
> > "On" are invalid parameters.
> > 
> > >                         fastcgi_buffer_size 128k;
> > >                         fastcgi_buffers 4 128k;
> > >          }
> > > 
> > >  
> > > 
> > > This does not work:
> > > 
> > >         location ~* \.(jpg|jpeg|gif|css|png|js|ico|tif)$ {
> > >                         access_log off;
> > >                         expires 30d;
> > >                         proxy_pass http://127.0.0.1;
> > >                         proxy_cache_key $scheme$host$request_uri
> > >                         proxy_cache cachestatic;
> > >                         proxy_cache_valid 200  1h;
> > >                         proxy_cache_valid 404  5m;
> > 
> > Why do you want to cache image from localhost ?
> > You should handle them as static files.
> > 
> > >                         break;
> > >         }
> > 
> > "break" is useless here. It's just waste of CPU cycles.
> > 
> > 
> > --------
> > 
> > So I should just really just use cache like this:
> >       location ~ \.php$ {
> > 
> >                          fastcgi_index index.php;
> >                          fastcgi_pass 127.0.0.1:9000;
> >                         fastcgi_cache cachephp;
> >                          fastcgi_cache_key 127.0.0.1:9000$request_uri;
> >                          fastcgi_cache_valid 200  1h;
> >                          include fastcgi_params;
> > 	}
> > 
> > And images like this:       
> > 	location ~* \.(jpg|jpeg|gif|css|png|js|ico|tif)$ {
> >                          access_log off;
> >                          expires 30d;
> > 	}
> > 
> > That would be best for performance?
> 
> Yes.
> 
> > Also, I noticed when I use the fastcgi_cache above that it caches logged
> in
> > pages and users see the wrong user profile... should I change the
> > fastcgi_cache_key to fix that?
> 
> Yes. Probably, you may add an user cookie.
> Actually, you should mark logged pages as non-cachable, otherwise transient
> proxy servers may cache them as well.
> 
> ------------------------
> 
> All pages on this site have a login option so I guess caching our site isn't
> a good idea. 

Yes, even if you cache them properly in nginx, they will have poor hit ratio.
However, you may try to cache non-personalized pages.


-- 
Igor Sysoev
http://sysoev.ru/en/



More information about the nginx mailing list