Would you like to learn how to redirect a URL on Nginx? In this tutorial, we are going to show you how to install the Nginx server and create a rule to redirect a specific URL on a computer running Linux.
• Ubuntu 18
• Ubuntu 19
• Ubuntu 20
• Nginx 1.18.0
Equipment list
The following section presents the list of equipment used to create this tutorial.
As an Amazon Associate, I earn from qualifying purchases.
Nginx – Related Tutorial:
On this page, we offer quick access to a list of tutorials related to Nginx.
Tutorial Nginx – Redirect a URL
Install the Nginx server.
Edit the Nginx configuration file for the default website.
Add the following line to create a permanent URL redirection using code 301.
Add the following line to create a temporary URL redirection using code 302.
Here is the file, before our configuration.
Here is the file, after our configuration.
Restart the Nginx service.
In our example, the Nginx server will redirect the TEST1 URL to the Google website using code 301.
In our example, the Nginx server will redirect the TEST2 URL to the Google website using code 302.
Code 301 is a permanent URL redirection.
Code 302 is a temporary URL redirection.
From a remote computer, test the URL redirection configured on the Nginx server.
Here is the command output.
Congratulations! You are able to configure a URL redirect on the Nginx server.