HTTP 404 on memcache misses

Hi

nginx + memcached in front of a tomcat farm, config looks like:

    location ~* ^/bla/bla.*$ {
            set $memcached_key $uri;
            if ( $uri ~ .*/$ ) {
                   set $index index.html;
                   set $memcached_key $uri$index;
            }
            memcached_pass     memcache;
            default_type       text/html;
            error_page         404 @fallback;
    }

    location @fallback {
            proxy_pass         http://tomcats;
    }

The first time the client accesses a page there’s a memcached miss and
the request is proxy_passed to the back-end tomcats, who generate the
page, save it to the cache and the HTML is returned to the client.
Everything OK but one detail: the HTTP 404 code from the memcached miss
reaches the client!

On subsequent accesses the client gets an HTTP 200 and the HTML served
from memcached, but on the first access nginx responds with an HTTP 404
AND the HTML code. Most browsers (tested with firefox, safari and lynx)
seem not to care about this 404 and render the page, but wget for
instance refuses to download the page the moment it receives the 404.

Tested on nginx 0.7.62 and .64.

Anybody else experiencing this behavior? Anything wrong with my config?
I guess this could lead to a series of problems, e.g. with Google if
you’re unfortunate enough to have an empty cache when it starts crawling
through your site.

Regards

Hello!

On Thu, Nov 19, 2009 at 01:48:25PM +0100, Vicente A. wrote:

            memcached_pass     memcache;
            default_type       text/html;
            error_page         404 @fallback;
  •             error_page         404 @fallback;
    
  •             error_page         404 = @fallback;
    

Tested on nginx 0.7.62 and .64.

Anybody else experiencing this behavior? Anything wrong with my config? I guess this could lead to a series of problems, e.g. with Google if you’re unfortunate enough to have an empty cache when it starts crawling through your site.

http://wiki.nginx.org/NginxHttpCoreModule#error_page

Maxim D.

Hi

El 19/11/2009, a las 17:08, Maxim D.
escribió:

  •             error_page         404 @fallback;
    
  •             error_page         404 = @fallback;
    

Cool! That = did it, now I’m getting 200. :slight_smile: I completely missed it on
the wiki. :-/

Thanks, Maxim!

Regards