# HTTP 404 on memcache misses

**URL:** <https://www.ruby-forum.com/t/http-404-on-memcache-misses/179199>\
**Category:** NGINX\
**Created:** [November 19, 2009, 1:53pm UTC](https://www.ruby-forum.com/t/http-404-on-memcache-misses/179199 "2009-11-19T13:53:40Z")\
**Posts on this page:** 3\
**Page:** 1

<div class="post-metadata">

**Author:** ![Vicente\_A](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/v/fbc32d/32.png) [@Vicente\_A](https://www.ruby-forum.com/u/Vicente_A)\
**Post date:** [November 19, 2009, 1:53pm UTC](https://www.ruby-forum.com/t/http-404-on-memcache-misses/179199/1 "2009-11-19T13:53:40Z")

</div>

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

---

<div class="post-metadata">

**Author:** ![Vicente\_A](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/v/fbc32d/32.png) [@Vicente\_A](https://www.ruby-forum.com/u/Vicente_A)\
**Post date:** [November 19, 2009, 5:12pm UTC](https://www.ruby-forum.com/t/http-404-on-memcache-misses/179199/2 "2009-11-19T17:12:41Z")

</div>

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.

> **[GitHub - nginxinc/nginx-wiki: ARCHIVED -- Source for the now archived NGINX Wiki...](https://github.com/nginxinc/nginx-wiki)**
>
> ARCHIVED -- Source for the now archived NGINX Wiki section of https://www.nginx.com

Maxim D.

---

<div class="post-metadata">

**Author:** ![Vicente\_A](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/v/fbc32d/32.png) [@Vicente\_A](https://www.ruby-forum.com/u/Vicente_A)\
**Post date:** [November 20, 2009, 8:57am UTC](https://www.ruby-forum.com/t/http-404-on-memcache-misses/179199/3 "2009-11-20T08:57:57Z")

</div>

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. 🙂 I completely missed it on  
the wiki. :-/

Thanks, Maxim!

Regards
