Introduction
Hi there! it is really important to handle unexpected HTTP response through web server if something went wrong with your application. Lets see how to show case your messages to the end users whenever something went wrong in your application.
Configuration update
Copy / Paste below configuration under http block in nginx.conf file and make sure that custom HTML pages which you have mentioned in the nginx.conf file exist under your document root. For example, here I have used /errorPage/HTTP404.html for 404 http response. So HTTP404.html file should be available under $root/errorPage location to display your customized 404 page.
1 2 3 4 5 6 7 8 | error_page 400 /errorPage/HTTP400.html error_page 401 /errorPage/HTTP401.html error_page 403 /errorPage/HTTP403.html error_page 404 /errorPage/HTTP404.html error_page 500 /errorPage/HTTP500.html error_page 501 /errorPage/HTTP501.html error_page 502 /errorPage/HTTP502.html error_page 503 /errorPage/HTTP503.html |
Sample custom HTML pages
If you don’t have customized HTML pages to display in your website, then you can use this link to download sample customized HTML page to use it in your application / website.
Footer notes
If you have multiple domains hosted in the same server and you want to display customized http response page for each domains, then you should use different custom pages file under different document root.
Once you update nginx.conf file, check the nginx syntax and reload | restart the application to update the changes.
1 2 3 | # nginx -t # service nginx reload|restart |
That’s it 😉 Now you can show case customized messages to your end users whenever the application behaves abnormal. If you have any queries, feel free to ask in comment section 😀