It is always better to show the helpful information to the users instead of the default raw message. In this guide, we’ll demonstrate how to configure Nginx to use custom error pages.
Let’s create a directory called errors in the root folder. Inside error folder, create a file called error_404.html for 404 error messages and create a file called error_50x.htlm for 500-level error messages.
Now open your nginx config file, generally, it will be located at
Open config file with vi editor (you can use other editor also)
error_page directive to serve custom pages which you have created, as shown below we will use error_page directive with location block.We will create a location block for the file, where we are able to ensure that the root matches our file system location and that the file is only accessible through internal Nginx redirects, not requestable directly by clients/visitors
Add this to consutome 404 error page –
Add this to serve custom 50x-level error page –
Here is the complete config file (
I hope you like this Post, Please feel free to comment below, your suggestion and problems if you face - we are here to solve your problems.
I am Arjun from Hyderabad (India). I have been working as a software engineer from the last 7+ years, and it is my passion to learn new things and implement them as a practice. Aside from work, I like gardening and spending time with pets.