Customize nginx default error pages

Whoaa it’s been a long time that i didn’t write any posts in the last year and it’s almost a year long.

Sorry, that is not important and the important one is how to customize white-default error pages on nginx like 502 and 503 pages. Until last week i was also still seeing 503 white error page on instagram previewer on its website. It’s likely that an eror occured on Instagram’s nginx server and then nginx displaying the error page.

Why the fuck they didn’t customize that page? As facebook bought them with an amount of billion dollars, i was not expecting to see the default error page. And i think that every website should considering to put nicer looks when something unwanted occured.

Basically, we can use error_page directive inside location directive on nginx configuration to deal with this issue. Example:

server {
  listen 80;
  location / {
    root /home/user/my_app; error_page 502 /502.html;

That’s it. It’s common error page customization as we can adjust it when nginx is configured as proxy or load balancer. If you’re using static assets you might need to add the file location like the sample below:

location /bg-error.png {
  root /home/user/my_app/images;

Hopefully it’s helpful and correct me if i’m wrong and sorry for harsh language.. :D

Tags: , ,

blog comments powered by Disqus