Nginx不从if表达式返回自定义错误页

Nginx不从if表达式返回自定义错误页,nginx,cdn,custom-error-pages,Nginx,Cdn,Custom Error Pages,这是我的CDN和conf文件,包含“几行” 情况真的很奇怪: 在配置方面,我有 error_page 403 = /e403; error_page 404 = /e404; 及 同时我有ARG fitler(禁止使用ARG,这是CDN): 当我请求/cookies.txt时,我有我的自定义404页面。当我请求一个或多个/cookies.txt?或/cookies.txt?时,我拥有nginx的404页面 问题是:为什么?当$if语句直接位于服务器块内时,我可以复制该问题,但当它们位于顶级位置

这是我的CDN和conf文件,包含“几行”

情况真的很奇怪:

在配置方面,我有

error_page 403 = /e403;
error_page 404 = /e404;

同时我有ARG fitler(禁止使用ARG,这是CDN):

当我请求
/cookies.txt
时,我有我的自定义404页面。当我请求一个或多个
/cookies.txt?
/cookies.txt?
时,我拥有nginx的404页面


问题是:为什么?

$if
语句直接位于
服务器
块内时,我可以复制该问题,但当它们位于顶级位置块内时,它可以正常工作。这对我很有用:

location / {
  if ($args !~ ^$){
    return 404;
  }
  if ($request ~* (^.*\?.*$)){
    return 404;
  }
}

当然,如果你有其他的位置块,你可能还需要
包括
那里的规则。

这很和蔼可亲,很棒!非常感谢。
if ($args !~ ^$){
    return 404;
}
if ($request ~* (^.*\?.*$)){
    return 404;
}
location / {
  if ($args !~ ^$){
    return 404;
  }
  if ($request ~* (^.*\?.*$)){
    return 404;
  }
}