apt update -y
apt install nagios4 -y
cd /etc/apache2/conf-available
cp nagios4-cgi.conf
cat > /etc/apache2/conf-enabled/nagios4-cgi.conf << EOL
ScriptAlias /cgi-bin/nagios4 /usr/lib/cgi-bin/nagios4
ScriptAlias /nagios4/cgi-bin /usr/lib/cgi-bin/nagios4
Alias /nagios4/stylesheets /etc/nagios4/stylesheets
Alias /nagios4 /usr/share/nagios4/htdocs
<DirectoryMatch (/usr/share/nagios4/htdocs|/usr/lib/cgi-bin/nagios4|/etc/nagios4/stylesheets)>
Options FollowSymLinks
DirectoryIndex index.php index.html
AllowOverride AuthConfig
AuthDigestDomain "nagios4"
AuthDigestProvider file
AuthUserFile "/etc/nagios4/htdigest.users"
AuthGroupFile "/etc/group"
AuthName "Restricted Nagios4 Access"
AuthType Digest
Require valid-user
</DirectoryMatch>
<Directory /usr/share/nagios4/htdocs>
Options +ExecCGI
</Directory>
EOL
a2enmod auth_digest authz_groupfile
htdigest -c /etc/nagios4/htdigest.users "Restricted Nagios4 Access" nagiosadmin
systemctl restart apache2
systemctl status apache2
systemctl restart nagios4
systemctl status nagios4