http-rewrite-status-filter #

Changes the status code of a response, optionally only when a condition is true. Use it when a backend returns the wrong status, for example to turn a 200 error page into a 404.

Source: upstream source

Directives

rewrite_status #

syntax: rewrite_status status;  ·  default: -  ·  context: http, server, location, http when, server when, location when

Rewrites the response status using the first matching rule in configuration order. With ngx_expr_module, a level with no rules or no matching when conditions falls back to the previous configuration level. An unconditional rule always matches. Once a rule matches, no further rule is evaluated, even if the target status equals the existing status.

Example

server {
    listen 127.0.0.1:8080;
    server_name localhost;

    location / {
        expr rewrite_to_404 !is_empty $http_rsp_404_status;
        when rewrite_to_404 {
            rewrite_status 404;
        }
        proxy_pass http://foo.com;
    }
}

↑ back to index