Take the 2-minute tour ×
Server Fault is a question and answer site for professional system and network administrators. It's 100% free, no registration required.

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 {
    server 127.0.0.1:11211;
}

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

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 {
    proxy_pass         http://127.0.0.1:7777;
    ...
    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

1 Answer 1

up vote 0 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 at 8:38

Your Answer

 
discard

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.