Would you like to learn how to enable the HSTS feature on the Nginx server? In this tutorial, we are going to show you how to enable on Nginx the feature called HTTP Strict Transport Security.

• 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 - Enable HSTS

Install the Nginx server.

Copy to Clipboard

Edit the Nginx configuration file for the website.

Copy to Clipboard

On the HTTPS area, add the following lines to this configuration file.

Copy to Clipboard

Optionally, include the PRELOAD option on the HSTS header.

Copy to Clipboard

Make sure that you have an HTTPS website configured on the Nginx server.

As an example, here is our configuration file.

Copy to Clipboard

Restart the Nginx service.

Copy to Clipboard

In our example, we configured the HSTS feature on the Nginx server.

From a remote Linux computer, try to access an HTTPS page.

Copy to Clipboard

Here is the command output.

Copy to Clipboard

Congratulations! You enabled the HSTS feature on the Nginx server.