proxy_cache ramdisk

AMP Admin admin at ampprod.com
Mon Feb 1 19:50:37 MSK 2010


-----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?

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?






More information about the nginx mailing list