VHosts and Directives, Part 3: Customize 404 error page in nginx

How to customize a 404 error page in nginx

We can Customize 404 error page in nginx at system level or domain level. In our case we are going to do it on a domain level.

1.) Create Custom 404 error page

cd /var/www/html/myexample/
echo "THIS IS OUR CUSTOM CONTENT DOES NOT EXIT PAGE - www.myexample.local - 404 error" > 404.html

2.) Edit Nginx configuration file

cd /etc/nginx/vhost.d/
vim www.myexample.local.conf

add following code under server section

error_page 404 = /404.html;
location = /404.html {
root /var/www/html/myexample;

3.) Use following command to make sure that you haven’t made any typos or added any invalid entries.

nginx -t

4.) Restart Nginx Service

systemctl restart nginx.service

5.) Video Tutorial

That’s all for now. Have questions, post them in the comments.

Add Comment