Server Fault is a question and answer site for system and network administrators. It's 100% free, no registration required.

Sign up
Here's how it works:
  1. Anybody can ask a question
  2. Anybody can answer
  3. The best answers are voted up and rise to the top

I'm using nginx as a reverse proxy to look up html content from memcached, if not present, then node.js, if not even there, node.js returns 404. What I'm trying to do is intercept and deliver a custom page for the 404 returned by node.js

The problem is that nginx doesn't return the correct 404.html but rather it's default one.

So while I can intercept the 404 page, nginx deliveres the default error page, not 404.html

upstream memcached {

error_page 404 /404.html;
location /404.html {

location @memcached {
    if ($memcached_request = 1) {
        memcached_pass memcached;
        error_page 404 502 504 = @nodejs;

    if ($memcached_request = 0) {
        error_page 404 502 504 = @nodejs;

location @nodejs {
    error_page 404 /404.html;
    proxy_intercept_errors on;
    proxy_redirect off;

location / {
    try_files $uri $uri/ @memcached;
    error_page 403 = @nodejs;

Is there a better way to do this "if not in memcached, go to node.js", instead of the error_page 404 = @fallback? If not, is there a way to catch the 404 from the last backend?

share|improve this question
up vote 1 down vote accepted

Maybe it doesn't want to redirect to an internal location? What if you try to redirect it to a named location again? I.e. @404?

Else, it may sound like you might have to enable recursive_error_pages for your setup to work.

share|improve this answer
Thank you! recursive_error_pages on worked perfectly! – dBi Jan 23 '14 at 8:38

Your Answer


By posting your answer, you agree to the privacy policy and terms of service.

Not the answer you're looking for? Browse other questions tagged or ask your own question.