Would you like to learn how to redirect HTTP to HTTPS on Nginx? In this tutorial, we are going to show you how to install the Nginx server and create a rule to redirect the HTTP traffic to HTTPS on a computer running Linux.
• 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.
Nginx – Related Tutorial:
On this page, we offer quick access to a list of tutorials related to Nginx.
Tutorial Nginx – Redirect HTTP to HTTPS
Install the Nginx server.
Edit the Nginx configuration file for the default website.
Add the following line to the configuration file.
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 all HTTP requests to HTTPS.
From a remote Linux computer, try to perform an HTTP access.
Here is the command output.
In our example, if a user tries to access the HTTP version of any page, he will be redirected to the HTTPS version of the same page.
Make sure that you have an HTTPS website configured on the Nginx server or the connection will be lost.
As an example, here is an Nginx configuration file with HTTP and HTTPS enabled.
Congratulations! You successfully configured the HTTP to HTTPS redirection on the Nginx server.