# Memcached, named locations, custom 404

**URL:** <https://www.ruby-forum.com/t/memcached-named-locations-custom-404/214633>\
**Category:** NGINX\
**Created:** [December 7, 2011, 6:15pm UTC](https://www.ruby-forum.com/t/memcached-named-locations-custom-404/214633 "2011-12-07T18:15:48Z")\
**Posts on this page:** 4\
**Page:** 1

<div class="post-metadata">

**Author:** ![dubstep](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/d/cdc98d/32.png) [@dubstep](https://www.ruby-forum.com/u/dubstep)\
**Post date:** [December 7, 2011, 6:15pm UTC](https://www.ruby-forum.com/t/memcached-named-locations-custom-404/214633/1 "2011-12-07T18:15:48Z")

</div>

Hi  
Is it possible to do a redirect from one named location to another?  
I’m using 1.0.10 and it does seem to stop processing in the first named  
location.  
Here’s an example (funny http codes do not matter):

server {

error\_page 404 /404.html;

location = /404.html {  
internal;  
}

location = /index.php {  
internal;  
error\_page 404 /404.html;  
error\_page 418 = @nocache;  
error\_page 303 = @process;  
if ($request\_method = POST) {  
return 418;  
}  
return 303;  
}

location @process {  
set $memcached\_key something$arg\_memkey;  
error\_page 404 502 = @nocache;  
memcached\_pass memcached;  
}

location @nocache {  
fastcgi\_pass backend;  
}

The premise was this. I don’t allow direct access to index.php, so I  
marked it internal. For a reason I don’t yet understand, if I don’t  
specify error\_page 404 in this location, nginx will show a standard 404  
error page, not the one defined at server level.  
Because memcached returns 404 if the key is not found, I had to move it  
to different location (conflict with internal’s 404).

So the GET request is passed to @process. And here’s the problem - if  
the key is found in memcached, everything works. But if the key is not  
found, the request is not passed to @nocache anymore (it returns 404 - I  
thought it would be handled by error\_page defined above), but the  
generic 404 nginx error page is returned.  
If I remove the “internal;” and error\_page 404 from location =/index.php  
and move the @process code there, everything works. So it looks I can’t  
pass the request from @process to @nocache.

If that’s the case, how would you solve this problem with an optimal  
configuration?

Thanks a lot!

relevant part of the debug log:  
2011/12/07 18:11:24 [info] 2089#0: \*5 key: “something/album/164” was not  
found by memcached while reading response header from upstream […]  
2011/12/07 18:11:24 [debug] 2089#0: \*5 finalize http upstream request:  
404  
2011/12/07 18:11:24 [debug] 2089#0: \*5 finalize http memcached request  
2011/12/07 18:11:24 [debug] 2089#0: \*5 free keepalive peer  
2011/12/07 18:11:24 [debug] 2089#0: \*5 free keepalive peer: saving  
connection 0A062054  
2011/12/07 18:11:24 [debug] 2089#0: \*5 event timer del: 9: 428017663  
2011/12/07 18:11:24 [debug] 2089#0: \*5 free rr peer 1 0  
2011/12/07 18:11:24 [debug] 2089#0: \*5 http finalize request: 404,  
“/index.php?page=album&id=164&memkey=/album/164” a:1, c:3  
2011/12/07 18:11:24 [debug] 2089#0: \*5 http special response: 404,  
“/index.php?page=album&id=164&memkey=/album/164”  
2011/12/07 18:11:24 [debug] 2089#0: \*5 http set discard body  
2011/12/07 18:11:24 [debug] 2089#0: \*5 charset: “” \> “utf-8”  
2011/12/07 18:11:24 [debug] 2089#0: \*5 HTTP/1.1 404 Not Found

Posted at Nginx Forum:

> **[memcached, named locations, custom 404](https://forum.nginx.org/read.php?2,219767,219767#msg-219767)**
>
> Hi Is it possible to do a redirect from one named location to another? I'm using 1.0.10 and it does seem to stop processing in the first named location. Here's an example (funny http codes do not matter): server { error\_page 404 /404.html;

---

<div class="post-metadata">

**Author:** ![danny000](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/d/58f4c7/32.png) [@danny000](https://www.ruby-forum.com/u/danny000)\
**Post date:** [December 7, 2011, 6:29pm UTC](https://www.ruby-forum.com/t/memcached-named-locations-custom-404/214633/2 "2011-12-07T18:29:27Z")

</div>

The missing part was recursive\_error\_pages on;  
I now know there are posts about it, but I can see them only now, when I  
googled for recursive\_error\_pages 🙂

Posted at Nginx Forum:

> **[Re: memcached, named locations, custom 404](https://forum.nginx.org/read.php?2,219767,219768#msg-219768)**
>
> Hi Is it possible to do a redirect from one named location to another? I'm using 1.0.10 and it does seem to stop processing in the first named location. Here's an example (funny http codes do not matter): server { error\_page 404 /404.html;

---

<div class="post-metadata">

**Author:** ![danny000](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/d/58f4c7/32.png) [@danny000](https://www.ruby-forum.com/u/danny000)\
**Post date:** [December 7, 2011, 6:30pm UTC](https://www.ruby-forum.com/t/memcached-named-locations-custom-404/214633/3 "2011-12-07T18:30:04Z")

</div>

Hello!

On Wed, Dec 07, 2011 at 12:14:59PM -0500, danny000 wrote:

> Hi  
> Is it possible to do a redirect from one named location to another?

Yes.

> I’m using 1.0.10 and it does seem to stop processing in the first named  
> location.

[…]

> **[Module ngx\_http\_core\_module](http://nginx.org/en/docs/http/ngx_http_core_module.html#recursive_error_pages)**
>
> This directive appeared in version 1.11.8.

Maxim D.

---

<div class="post-metadata">

**Author:** ![danny000](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/d/58f4c7/32.png) [@danny000](https://www.ruby-forum.com/u/danny000)\
**Post date:** [December 7, 2011, 6:39pm UTC](https://www.ruby-forum.com/t/memcached-named-locations-custom-404/214633/4 "2011-12-07T18:39:20Z")

</div>

I beat you to it 😉 But thanks a lot for a quick response and for the  
ngx\_http\_upstream\_keepalive too!

Posted at Nginx Forum:

> **[Re: memcached, named locations, custom 404](https://forum.nginx.org/read.php?2,219767,219770#msg-219770)**
>
> Hi Is it possible to do a redirect from one named location to another? I'm using 1.0.10 and it does seem to stop processing in the first named location. Here's an example (funny http codes do not matter): server { error\_page 404 /404.html;
