Home > Software design >  Disable direct access to nginx custom error page
Disable direct access to nginx custom error page

Time:12-15

I have this nginx block that redirects all 401,403 and 404 to a single custom error page

error_page 401 @errorPage;
error_page 403 @errorPage;
error_page 404 @errorPage;
location @errorPage {
    rewrite ^ /error.php?error=$status last;
}

Is it possible to deny the access to the error.php if called directly? Thanks

CodePudding user response:

Consider storing error pages outside of the main web folder and set a new root or alias:

location @errorPage {
  root /var/www/error-pages;
  ...
}
  • Related