Would you like to learn how to install Nginx and configure the basic authentication feature on a computer running Ubuntu Linux? In this tutorial, we are going to configure the Basic authentication feature on the Nginx server.

• 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.

Tutorial Nginx - Basic authentication

Install the Nginx server and the required packages.

Copy to Clipboard

Create the Nginx password file and add the first user account.

Copy to Clipboard

The system will request you to enter the password to the new user account.

Copy to Clipboard

Here is the file content.

Copy to Clipboard

To create additional user accounts, use the following command.

Copy to Clipboard

Edit the Nginx configuration file for the default website.

Copy to Clipboard

Insert the following line in the area named LOCATION.

Copy to Clipboard

Here is the file content.

Copy to Clipboard

Restart the Nginx service.

Copy to Clipboard

Open your browser and enter the IP address of your web server.

In our example, the following URL was entered in the Browser:

• http://172.31.8.195

The Nginx server will require you to perform the user authentication.

Nginx authentication

In our example, the configuration required user authentication to access any part of the website.

In the next example, we will require authentication only to users trying to access a subdirectory named: SECURE.

Copy to Clipboard

Congratulations! You are now able to use the Nginx basic authentication.