Memcached, named locations, custom 404

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:
http://forum.nginx.org/read.php?2,219767,219767#msg-219767

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 :slight_smile:

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

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.

[…]

http://nginx.org/en/docs/http/ngx_http_core_module.html#recursive_error_pages

Maxim D.

I beat you to it :wink: But thanks a lot for a quick response and for the
ngx_http_upstream_keepalive too!

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

This forum is not affiliated to the Ruby language, Ruby on Rails framework, nor any Ruby applications discussed here.

| Privacy Policy | Terms of Service | Remote Ruby Jobs