openresty error_page不生效问题

openresty的大佬们看过来,有个小需求,要求重定向返回404后,再去获取默认页面;location里配置error_page 404 =/fallback;配置完成之后发现重定向400的错误竟然无效了。。
location里配置error_page 404 =/fallback之前

img


nginx.conf配置:

worker_processes  1;

events {
    worker_connections  1024;
}
http {
    include       mime.types;
    default_type  application/octet-stream;

    sendfile        on;
    
    keepalive_timeout  65;
    
    init_worker_by_lua_file luascripts/inti_worker.lua;
    
    server {
        listen       80;
        server_name  localhost;

        location =/test {
            
            rewrite_by_lua_block{
                ngx.log(ngx.ERR,"++++++++first request http:localhost/test+++++++++");
            }
            
            #400错误
            proxy_pass   https://blog.csdn.net/test?biz_id=%9e;
            
            #404错误
            #proxy_pass   https://www.baidu.com/test;
            
            #proxy_intercept_errors on;
            #recursive_error_pages on;
            #error_page 404 = /fallback;
            
        }
        location /fallback{
            rewrite_by_lua_block{
                ngx.log(ngx.ERR,"++++++兜底url++++++++");
            }
            
            proxy_pass   https://www.baidu.com/test;
        }
        
        proxy_intercept_errors on;
        recursive_error_pages on;
        error_page  400              /400.html;
        location = /400.html {
            content_by_lua_block{
               ngx.say("400:Bad Request");
            }
        }
        error_page  404              /404.html;
        location = /404.html {
            content_by_lua_block{
               ngx.say("404:NOT FOUND");
            }
        }
    }
}

location里配置error_page 404 =/fallback之后

img


nginx.conf配置:

worker_processes  1;

events {
    worker_connections  1024;
}
http {
    include       mime.types;
    default_type  application/octet-stream;

    sendfile        on;
    
    keepalive_timeout  65;
    
    init_worker_by_lua_file luascripts/inti_worker.lua;
    
    server {
        listen       80;
        server_name  localhost;

        location =/test {
            
            rewrite_by_lua_block{
                ngx.log(ngx.ERR,"++++++++first request http:localhost/test+++++++++");
            }
            
            #400错误
            proxy_pass   https://blog.csdn.net/test?biz_id=%9e;
            
            #404错误
            #proxy_pass   https://www.baidu.com/test;
            
            proxy_intercept_errors on;
            recursive_error_pages on;
            error_page 404 = /fallback;
            
        }
        location /fallback{
            rewrite_by_lua_block{
                ngx.log(ngx.ERR,"++++++兜底url++++++++");
            }
            
            proxy_pass   https://www.baidu.com/test;
        }
        
        proxy_intercept_errors on;
        recursive_error_pages on;
        error_page  400              /400.html;
        location = /400.html {
            content_by_lua_block{
               ngx.say("400:Bad Request");
            }
        }
        error_page  404              /404.html;
        location = /404.html {
            content_by_lua_block{
               ngx.say("404:NOT FOUND");
            }
        }
    }
}

两次nginx.conf不同之处就是再第二次放开了如下配置:
proxy_intercept_errors on;
recursive_error_pages on;
error_page 404 = /fallback;
第一次拦截了400的错,按照我想要的返回结果,但是在location里配了error_page 之后发现400的错server块的error_page不生效了,直接把这个urlhttps://blog.csdn.net/test?biz_id=%9e 的错误返回给我了。
为什么在location里配了error_page 404之后,server块的error_page就不生效了,哪位C友能解释下哦