NGINX: Create Custom 404 / 403 Error Pages on Linux or Unix

NGINX: Create Custom 404 / 403 Error Pages on Linux or Unix

To create custom 404 (Not Found) and 403 (Forbidden) error pages on an NGINX server running on Linux or Unix, you can follow these steps:

  1. Create the custom error pages as HTML files. You can use a text editor to create the HTML files and customize the content and layout as desired.

  2. Save the HTML files to a location on the server. For example, you can save them to the /usr/share/nginx/html directory.

  3. Edit the NGINX configuration file to specify the locations of the custom error pages. The configuration file is typically located at /etc/nginx/nginx.conf or /etc/nginx/conf.d/default.conf.

Add the following lines to the configuration file to specify the locations of the custom 404 and 403 error pages:

refer to‮tual:‬turi.com
error_page 404 /404.html;
error_page 403 /403.html;
location = /404.html {
  root /usr/share/nginx/html;
}
location = /403.html {
  root /usr/share/nginx/html;
}

Replace /usr/share/nginx/html with the location where you saved the HTML files.

  1. Restart the NGINX server to apply the changes. You can use the following command to restart the server:
systemctl restart nginx
  1. Test the custom error pages by accessing a URL that does not exist on the server or by attempting to access a restricted resource. The custom error pages should be displayed instead of the default NGINX error pages.

For more information about customizing error pages in NGINX, you can refer to the NGINX documentation or search online for tutorials and examples.

Created Time:2017-10-30 10:17:51  Author:lautturi