Show a 404 with auth_request

The 404 error_page is using $errorsroot variable set by auth_request so that a different error page can be shown based on the user auth. For example if there’s no auth the 404 should be /html/noauth.html otherwise /html/yesauth.html.

location / {
  auth_request /auths
  auth_request_set $errorsroot $upstream_http_errorsroot;
  error_page 401 403 404 = @noauth;
  try_files $uri/index.html =404;
}

error_page 404 @errors404;
location @errors404 {
  root /html$errorsroot;
}

location = /auths {
  internal;
  proxy_pass http://your_auth_service;
  proxy_pass_request_body off;
  proxy_set_header Content-Length "";
}

It works for all pages that don’t exist except for when someone goes to /auths. It’s internal so I want to treat it like any other missing page if someone accesses it.

If someone goes to /nopage which doesn’t exist, auth_request is done first and the proper error_page will be loaded from root /html$errorsroot. If someone goes to /auths directly how can I do the same thing?

There’s the same problem with any location that is internal.

location /dontshow {
  internal;
}

If I load /dontshow/page it should be 404 and show the page from root /html$errorsroot; but it doesn’t.

Anyone know how to fix this?