How to Create Custom Error Pages for Nginx

In a previous posts, we have discussed the finer points of creating custom error pages for an Apache web server installation. But what should you do if your web server is Nginx rather than Apache? The process of configuring an error page is somewhat different.

To begin, you will need to create a normal HTML document, just as you would for an Apache error page. You can make the contents of the page whatever you want. Assuming you are making a 404 Not Found error page, you should definitely include that message somewhere in the document. When you are finished, save the file to your document root. The location may vary depending on your operating system, but the default location should be something like  /usr/local/nginx/html

The next step is to edit the Ngnix configuration file and add the correct information. You may find the configuration file at this location: /usr/local/nginx/conf/nginx.conf

Find the line in the file that mentions the error code you want to change. If the line is not there, you can append it to the end of the file. It should look like this:

error_page   404  =  /404-notfound.html;

That is all it takes for a basic error page. You can add one for each error code. Whenever an error is triggered by a user, the web server will locate the file you have specified and display its contents.

For more information about error docs or the web server in general, consult the Nginx documentation.

Related Posts











Comments: