Would you like to learn how to configure an Nginx server to use RADIUS authentication? In this tutorial, we are going to show you how to authenticate the Nginx service using a Freeradius server installed on a computer running Ubuntu Linux.

• Ubuntu 20
• Ubuntu 19
• Ubuntu 18
• 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 – FreeRadius Server Installation on Ubuntu Linux

• IP – 192.168.15.10
• Operacional System – Ubuntu 20.04
• Hostname – FREERADIUS

On the Linux console, use the following commands to install the FreeRadius service.

Copy to Clipboard

Now, we need to add FreeRadius clients to the file named: Clients.conf.

Locate and edit this file.

Copy to Clipboard

Add the following lines at the end of the clients.conf file.

Copy to Clipboard

In our example, we are adding 1 client device:

The device was named PROXYAUTH and has the IP address 192.168.15.30.

Now, we need to add FreeRadius users to the configuration file named: USERS.

Locate and edit this file.

Copy to Clipboard

Add the following lines at the end of the file

Copy to Clipboard

In our example, we are adding 2 user accounts.

The first user account was named Admin.

The second user account was named Bruno.

Restart the Freeradius server.

Copy to Clipboard

Test your radius server configuration file.

Copy to Clipboard

You have finished the Freeradius installation on Ubuntu Linux.

Freeradius Authentication Test

Test your radius authentication locally using the following commands:

Copy to Clipboard

Here is the command output:

Copy to Clipboard

As you can see, the Bruno Account was able to successfully authenticate on the Radius server.

Test the user account named Admin.

Copy to Clipboard

Here is the command output:

Copy to Clipboard

As you can see, the Admin Account was able to successfully authenticate on the Radius server.

Tutorial Nginx – RADIUS authentication

• IP – 192.168.15.20
• Operational System – Ubuntu 20.04
• Hostname – NGINX

Install the Nginx server.

Copy to Clipboard

Edit the Nginx configuration file for the default website.

Copy to Clipboard

Here is the file before our configuration.

Copy to Clipboard

Here is the file after our configuration.

Copy to Clipboard

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

Nginx does not have native RADIUS authentication.

The authentication information sent to Nginx will be forwarded to the web server 192.168.15.30.

If the remote server validates the user authentication, Nginx will authorize the user access.

Restart the Nginx service.

Copy to Clipboard

You have finished the Nginx required configuration.

Nginx – Using Apache as the authentication proxy

• IP – 192.168.15.30
• Operational System – Ubuntu 20.04
• Hostname – APACHE

Now, we need to configure the remote server that will be responsible for the credential validation.

In our example, we are going to use an Apache server to validate the user credential on the RADIUS server.

Install the Apache server and the required RADIUS authentication module.

Copy to Clipboard

Enable the Apache2 RADIUS authentication module.

Copy to Clipboard

Create a directory named AUTH and give the user named www-data permission over this directory.

Copy to Clipboard

Configure the Apache server to request the RADIUS authentication to users trying to access this directory.

Edit the Apache configuration file for the default website.

Copy to Clipboard

Here is the configuration file before our configuration.

Copy to Clipboard

Here is the file after our configuration.

Copy to Clipboard

The Apache server was configured to request password authentication to access the directory named AUTH.

The Apache web server was configured to authenticate user accounts using the RADIUS server 192.168.15.10.

Restart the Apache service.

Copy to Clipboard

Congratulations! You successfully configured the Apache authentication.

Nginx – RADIUS authentication test

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

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

• http://192.168.15.20

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

Nginx authentication

After a successful login, you will be authorized to access the website.

nginx welcome

Congratulations! You configured the RADIUS authentication on the Nginx server.