I’m working on a website, and if the user isn’t authenticated or doesn’t have permission to view the specified page, I want to throw the standard 404 page. I’ve done a little bit of looking, but no luck. Obviously I could just copy the HTML, but I’d rather not. I’d rather use the actual 404 page that nginx uses, if possible.
Where can I find this?
Run
nginx -Vand look for the path defined by--prefix=/prefix/path/to/nginx.You will find the default 404 file as
404.htmlunder/prefix/path/to/nginx/htmlA better way to editing the default file when you want custom error pages is to add a block such as this to your nginx.conf file under the http section
This basically says use
/error_docs/404_not_found.htmlif a 404 error is generated. You obviously define those for which you want to make a specific custom pageYou can then save the 404_not_found.html file somewhere on your server such as
/prefix/path/to/nginx/errorsand then, under each server section, add something likeWhenever any of the previously defined error codes are thrown, the predefined custom page will be served.