Caching + Error_code inefficiences

icqheretic nginx-forum at nginx.us
Tue Aug 25 09:05:26 MSD 2009


Sorry about the partial repost. I misclicked the POST button early on and ran into the edit restrictions. Disregard the top.

Consider:

     
     fastcgi_cache_path             storage/cache levels=2:2 keys_zone=cacheresp:50m inactive=25m max_size=2000M;
     fastcgi_temp_path              storage/temp/;
     fastcgi_cache_valid             any 10s;

    location / {
            root            html;
            index           index.html;

            fastcgi_pass    unix:/tmp/php-fcgi.socket
            include        fastcgi_params;

            fastcgi_cache          cfcheckresp;
            
            error_page 404 = @backend;
    }

   location @backend {
        proxy_pass http://127.0.0.1:8070;
   }


The idea is that if fastcgi returns a 404 then the backend handles the request. The backend's response should never be cached.  This part works great.  What doesn't... is that the 404 is never cached (the fastcgi script is hardcoded to always return "Cache-Control: max_age=5"). Fastcgi is consulted again and again when a 404 is hit. If any other code is hit it caches just fine for 5 full 5 seconds.  It would be great if the 404 result was cached. Any thoughts on accomplishing this? Am I missing something?

By the way, the same goes if you use try_files() in place of error_page(). And I believe the same happens when a x-accel-redirect is issued.

Posted at Nginx Forum: http://forum.nginx.org/read.php?2,5143,5145#msg-5145






More information about the nginx mailing list