Ubuntu 26.04

Nginx : Basic Authentication + PAM2026/05/27

 

Configure Nginx to use OS users on Basic authentication.

[1]

Username and password are sent with plain text on Basic Authentication,
so Use secure connection with SSL/TLS setting, refer to here.

[2] Install packages which includes [mod-http-auth-pam] module.
root@www:~#
apt -y install nginx-extras
[3] Configure Basic authentication + PAM.
For example, set Basic Authentication to the directory [/var/www/html/auth-pam].
root@www:~#
vi /etc/nginx/sites-available/default
# add settings into [server] section in a virtualhost you'd like to set

server {
.....
.....
       location /auth-pam {
           auth_pam "PAM Authentication";
           auth_pam_service_name "nginx";
       }
.....
.....

root@www:~#
vi /etc/pam.d/nginx
# create new

auth       include      common-auth
account    include      common-account

# add to a group that nginx can read shadow

root@www:~#
usermod -aG shadow www-data

root@www:~#
systemctl reload nginx

# create a test page

root@www:~#
mkdir /var/www/html/auth-pam

root@www:~#
vi /var/www/html/auth-pam/index.html
<html>
<body>
<h1 style="width: 100%; font-size: 40px; text-align: center;">
Test Page for PAM Auth
</h1>
</body>
</html>
[4] Access to the test page from any client computer with web browser. Then authentication is required as settings, answer with any OS user.
[5] That's OK if authentication is successfully passed and test page is displayed normally.
Matched Content