Openresty/Lua返回默认错误页面而不是自定义

我目前正在尝试使用此脚本设置WAF / DDOS保护: https://github.com/C0nw0nk/Nginx-Lua-Anti-DDoS/blob/master/lua/anti_ddos_challenge.lua

除了Openresty / nginx返回默认的500错误页面而不是下面显示的自定义error_page之外,一切都运作良好,如果其中一个WAF规则被命中。请参见上面的脚本中的“WAF_URI_Request_table”。

每次请求被这些WAF规则阻止时,我还会在日志中获得以下条目:

2020/07/27 09:20:29 [error] 150#150: * 16在内部重定向到“/ 403.html”时重写或内部重定向周期,客户端:172.21.0.5,服务器:localhost,请求:“GET /test.php HTTP /1.1”,主机:“localhost”

我的nginx配置如下(缩短):

... 
http {
     upstream backend {
        server 127.0.0.1:8000 max_fails = 3 fail_timeout = 60s;
     }
... 
 server {
        listen 80;
        access_by_lua_file ddos_challenge.lua;
        aio threads = default;
... 
location @ proxy_to_app {
            proxy_pass http://backend;
            aio threads;
            proxy_read_timeout 100s;
            proxy_connect_timeout 100s;
            proxy_http_version 1.1;
            proxy_redirect off;
            proxy_buffers 16 4k;
            proxy_buffer_size 2k;
            proxy_intercept_errors on;
            proxy_set_header Host $host;
            uwsgi_intercept_errors on;
            gzip on;
            gzip_min_length 1024;
            gzip_comp_level 3;
            gzip_vary on;
            gzip_disable msie6;
            gzip_proxied expired no-cache no-store private auth;
            gzip_types text/css text/javascript text/xml text/plain text/x-component application/javascript application/x-javascript application/json application/xml application/rss+xml application/atom+xml font/truetype font/opentype application/vnd.ms-fontobject image/svg+xml;
            }

location / {
            try_files $uri @ proxy_to_app;
            }
... 
error_page 412 414 416 444 495 496 497 500 501 502 504 507 /custom_error.html;
        location = /custom_error.html {
            root /app/templates/;
            internal;
        }
点赞
用户88888888
用户88888888

发现了错误,参见:

https://groups.google.com/g/openresty-en/c/1XASYFeP61o?pli=1

我将 access_by_lua 行移动到了 / 位置块中,就是这样。

2020-07-27 11:10:14