Forum: NGINX x-accel-redirect and status codes

Announcement (2017-05-07): www.ruby-forum.com is now read-only since I unfortunately do not have the time to support and maintain the forum any more. Please see rubyonrails.org/community and ruby-lang.org/en/community for other Rails- und Ruby-related community platforms.
87d08bdf14ef944738d2a81105b12606?d=identicon&s=25 Brian Moran (Guest)
on 2009-04-07 23:41
(Received via mailing list)
We'd like nginx to be able to return a 404 error page using
x-accel-redirect, BUT also have the status code returned to be 404; is
this possible?
thanks,
A8108a0961c6087c43cda32c8616dcba?d=identicon&s=25 Maxim Dounin (Guest)
on 2009-04-07 23:57
(Received via mailing list)
Hello!

On Tue, Apr 07, 2009 at 02:32:46PM -0700, Brian Moran wrote:

> We'd like nginx to be able to return a 404 error page using
> x-accel-redirect, BUT also have the status code returned to be 404; is
> this possible?

I don't actually understand reason - if you want 404 content to be
returned by frontend, you may use proxy_intercept_errors.

But if you really want to, try something like this:

    location = /redirect-404-here {
        error_page  404  /404.html;
        return 404;
    }

    location = /404.html {
        # here actual content should be returned
        # it will have 404 status
        ...
    }

and return "X-Accel-Redirect: /redirect-404-here".  If you want
the same for multiple different files - it's easy too, just use
variables in error_page uri.

Maxim Dounin
This topic is locked and can not be replied to.