harbor run -t LiteCoder/nginx-custom-error-pagesharbor download LiteCoder/nginx-custom-error-pagesConfigure a production-ready Nginx web server on Ubuntu with custom error pages for HTTP errors 404, 500, 502, 503, and 504.
nginx -t syntax checkCreate custom HTML error pages at the following paths:
/var/www/html/errors/404.html/var/www/html/errors/500.html/var/www/html/errors/502.html/var/www/html/errors/503.html/var/www/html/errors/504.htmlEach error page must:
<!DOCTYPE html>, <html>, <head>, and <body> tags.<title> tag containing the corresponding error code (e.g., 404).<h1> tag (e.g., the text 404 must appear inside an <h1>).<a> tag) with href="/" to navigate back to the home page.<style> block with CSS styling (inline in the HTML file).Modify the Nginx site configuration (the default site config under /etc/nginx/sites-available/ or /etc/nginx/conf.d/) so that:
server block listens on port 80.root directive points to /var/www/html.error_page directive maps the code to the corresponding file under /errors/ (e.g., error_page 404 /errors/404.html;).location block for /errors/ is defined with internal; so that error pages are not directly browsable.curl -s -o /dev/null -w "%{http_code}" http://localhost/nonexistent-page must return status code 404, and curl -s http://localhost/nonexistent-page must contain the custom 404 page content (the <h1> with 404 and the back-to-home link).http://localhost/errors/404.html directly must NOT serve the file (because of the internal directive).