Would you like to learn how to redirect the 404 error to a specific URL on the Nginx server? In this tutorial, we are going to configure the Nginx server to redirect the 404 error to a specific page.

• Ubuntu 18
• Ubuntu 19
• Ubuntu 20
• Nginx 1.18.0

In our example, the Nginx server is hosting the website WWW.GAMEKING.TIPS

Equipment list

The following section presents the list of equipment used to create this tutorial.

As an Amazon Associate, I earn from qualifying purchases.

Tutorial Nginx - Redirect the error 404 to a page

Install the Nginx server.

Copy to Clipboard

Edit the Nginx configuration file for the default website.

Copy to Clipboard

Add the following line to the configuration file.

Copy to Clipboard

Here is the file, before our configuration.

Copy to Clipboard

Here is the file, after our configuration.

Copy to Clipboard

Restart the Nginx service.

Copy to Clipboard

In our example, the Nginx server will redirect the 404 errors to a specific URL.

From a remote Linux computer, try to access a page that does not exist.

Copy to Clipboard

Here is the command output.

Copy to Clipboard

In our example, the 404 error was redirected to a specific URL using a 302 code.

There are multiple ways to redirect an error page using Nginx.

Copy to Clipboard

Congratulations! You redirected the 404 errors on the Nginx server.