Nginx not returning custom error pages from if expression Nginx not returning custom error pages from if expression nginx nginx

Nginx not returning custom error pages from if expression


I can replicate the problem when the $if statements are directly inside the server block, but it works correctly when they are inside a top-level location block. This worked for me:

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

Of course, if you have other location blocks, you may need to include the rules there too.