How To Set Up Password Authentication with Nginx on Ubuntu 14.04

How To Set Up Password Authentication with Nginx on Ubuntu 14.04

How To Set Up Password Authentication with Nginx on Ubuntu 14.04

Securing your Nginx web server with password authentication is an important step to protect your website and its contents from unauthorized access. In this tutorial, we will walk you through the steps to set up password authentication on an Ubuntu 14.04 server running Nginx.

Step 1 - Install Apache2 Utilities

The first step is to install Apache2 utilities, which includes htpasswd, a utility that allows us to create and manage user authentication credentials.

sudo apt-get update
sudo apt-get install apache2-utils

Step 2 - Create a Password File

Next, we will create a password file that will contain the usernames and passwords for authentication. In this example, we will create a file called "passwords" in the /etc/nginx directory.

sudo htpasswd -c /etc/nginx/passwords username

Replace "username" with the username you would like to use for authentication. You will be prompted to enter and confirm a password for the user.

To add additional users to the password file, omit the -c option:

sudo htpasswd /etc/nginx/passwords username2

Step 3 - Configure Nginx

Next, we will configure Nginx to use our password file for authentication.

Edit the Nginx configuration file:

sudo nano /etc/nginx/sites-available/default

Add the following lines inside the server block:

auth_basic "Restricted Content";
auth_basic_user_file /etc/nginx/passwords;

Save and close the file.

Step 4 - Restart Nginx

Finally, restart Nginx for the changes to take effect:

sudo service nginx restart

That's it! Your Nginx web server is now secured with password authentication.

Keywords: Nginx, Ubuntu, Password Authentication, Tutorial, Apache2 Utilities, htpasswd, Password File, Configure Nginx, Server Block, Restart Nginx.

Комментарии

Популярные сообщения из этого блога

How To Modify CSS Classes in JavaScript

How To Backup MySQL Databases on an Ubuntu VPS

How To Backup PostgreSQL Databases on an Ubuntu VPS