【发布时间】:2018-02-05 08:05:43
【问题描述】:
如果在 nginx 中发现错误(例如 404、403..等),我正在尝试显示自定义错误页面。当我使用以下配置访问 /test 时显示 404 错误页面。
error_page 403 /403.html;
error_page 404 /404.html;
location = /403.html {
root /usr/share/nginx/html/errors;
allow all;
}
location = /404.html {
root /usr/share/nginx/html/errors;
allow all;
}
# Everything is a 404
location /test {
return 404; #return the code 404
}
之后,我尝试添加基于 geoip 模块的条件检查。如果$deny_request等于1,nginx会直接返回403。
# Geoip checking to set deny request value.
if ($blocked_country) {
set $deny_request 1;
}
if ($deny_request = 1) {
return 403;
}
http 状态 403 按预期返回。但是,它不是自定义错误页面,而是返回 nginx 默认的 403 错误页面。似乎不可能使用自定义错误页面检查服务器块。我错过了什么吗?
【问题讨论】:
标签: nginx geoip custom-error-pages