fix error pages for default http server
This commit is contained in:
parent
0afe038aa5
commit
915b51c3b9
|
@ -1,32 +1,43 @@
|
|||
{% set default_errors = ["400", "401", "403", "404", "405", "413", "429", "500", "501", "502", "503", "504"] %}
|
||||
{% if ERRORS != "" %}
|
||||
{% for element in ERRORS.split(" ") %}
|
||||
{% set code = element.split("=")[0] %}
|
||||
{% set page = element.split("=")[1] %}
|
||||
error_page {{ code }} {{ page }};
|
||||
|
||||
{% 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
|
||||
}
|
||||
location = {{ page }} {
|
||||
root {% if ROOT_FOLDER == "" %}/var/www/html/{% if MULTISITE == "yes" %}{{ SERVER_NAME.split(" ")[0] }}{% endif %}{% else %}{{ ROOT_FOLDER }}{% endif %};
|
||||
modsecurity off;
|
||||
internal;
|
||||
}
|
||||
{% endif %}
|
||||
{% endfor %}
|
||||
{% endfor %}
|
||||
{% endif %}
|
||||
|
||||
{% 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';
|
||||
root /usr/share/bunkerweb/core/errors/files;
|
||||
content_by_lua_block {
|
||||
local logger = require "bunkerweb.logger"
|
||||
local cerrors = require "errors.errors"
|
||||
local errors = cerrors:new()
|
||||
if ngx.status == 200 then
|
||||
errors:render_template(tostring(405))
|
||||
else
|
||||
errors:render_template(tostring(ngx.status))
|
||||
end
|
||||
}
|
||||
}
|
||||
|
||||
{% endif %}
|
||||
{% endfor %}
|
||||
{% endif %}
|
Loading…
Reference in New Issue