Add setting to intercept specifics error codes
This commit is contained in:
parent
86c81a6218
commit
c4b5ddb950
|
@ -12,36 +12,37 @@ location = {{ page }} {
|
|||
{% endfor %}
|
||||
{% endif %}
|
||||
|
||||
{% set default_errors = ["400", "401", "403", "404", "405", "413", "429", "500", "501", "502", "503", "504"] %}
|
||||
|
||||
{% for default_error in default_errors %}
|
||||
{% if not default_error + "=" in ERRORS +%}
|
||||
{% if default_error == "405" +%}
|
||||
error_page 405 =200 @405;
|
||||
{% else +%}
|
||||
error_page {{ default_error }} @{{ default_error }};
|
||||
{% endif +%}
|
||||
location @{{ default_error }} {
|
||||
auth_basic off;
|
||||
internal;
|
||||
modsecurity off;
|
||||
default_type 'text/html';
|
||||
content_by_lua_block {
|
||||
local logger = require "logger"
|
||||
local errors = require "errors.errors"
|
||||
local html, err
|
||||
if ngx.status == 200 then
|
||||
html, err = errors.error_html(tostring(405))
|
||||
else
|
||||
html, err = errors.error_html(tostring(ngx.status))
|
||||
end
|
||||
if not html then
|
||||
logger.log(ngx.ERR, "ERRORS", "Error while computing HTML error template for {{ default_error }} : " .. err)
|
||||
else
|
||||
ngx.say(html)
|
||||
end
|
||||
{% if INTERCEPTED_ERROR_CODES != "" %}
|
||||
{% for intercepted_error_code in INTERCEPTED_ERROR_CODES.split(" ") %}
|
||||
{% if not intercepted_error_code + "=" in ERRORS +%}
|
||||
{% if intercepted_error_code == "405" +%}
|
||||
error_page 405 =200 @405;
|
||||
{% else +%}
|
||||
error_page {{ intercepted_error_code }} @{{ intercepted_error_code }};
|
||||
{% endif +%}
|
||||
location @{{ intercepted_error_code }} {
|
||||
auth_basic off;
|
||||
internal;
|
||||
modsecurity off;
|
||||
default_type 'text/html';
|
||||
content_by_lua_block {
|
||||
local logger = require "logger"
|
||||
local errors = require "errors.errors"
|
||||
local html, err
|
||||
if ngx.status == 200 then
|
||||
html, err = errors.error_html(tostring(405))
|
||||
else
|
||||
html, err = errors.error_html(tostring(ngx.status))
|
||||
end
|
||||
if not html then
|
||||
logger.log(ngx.ERR, "ERRORS", "Error while computing HTML error template for {{ intercepted_error_code }} : " .. err)
|
||||
else
|
||||
ngx.say(html)
|
||||
end
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
{% endif %}
|
||||
{% endfor %}
|
||||
{% endif %}
|
||||
{% endfor %}
|
||||
{% endif %}
|
|
@ -13,6 +13,15 @@
|
|||
"label": "Errors",
|
||||
"regex": "^(?! )( ?([1-5]\\d{2})(?!.*\\2(?![^=]))=(/[\\w\\].~:/?#[@!$&'()*+,;=-]*)(?!.*\\3(?!.)))*$",
|
||||
"type": "text"
|
||||
}
|
||||
},
|
||||
"INTERCEPTED_ERROR_CODES": {
|
||||
"context": "multisite",
|
||||
"default": "400 401 403 404 405 413 429 500 501 502 503 504",
|
||||
"help": "List of HTTP error code intercepted by Bunkerweb",
|
||||
"id": "intercepted-error-codes",
|
||||
"label": "Intercepted error codes",
|
||||
"regex": "^.*$",
|
||||
"type": "text"
|
||||
}
|
||||
}
|
||||
}
|
||||
|
|
Loading…
Reference in New Issue