Freebsd – Apache 403 Forbidden for Nagios on FreeBSD

apache-2.4freebsd

I have the following conf file in /usr/local/etc/apache24/Includes and when I try to sign in to Nagios GUI, I get a 403 forbidden. I guess this a permissions issue with Apache accessing Nagios data, but I am not sure how to resolve this. I did add www user to nagios group and the files are in /usr/local/www/nagios/cgi-bin/ are executable and readable by nagios group. I also have cgi_modules enabled in the httpd.conf file

ScriptAlias /nagios/cgi-bin/ /usr/local/www/nagios/cgi-bin/

Alias /nagios /usr/local/www/nagios/
<Directory /usr/local/www/nagios>

   Options None
   AllowOverride None
   Order allow,deny
   Allow from all
   AuthName "Nagios Access"
   AuthType Basic
   AuthUSerFile /usr/local/etc/nagios/htpasswd.users
   Require valid-user

</Directory>

<Directory /usr/local/www/nagios/cgi-bin>

   Options ExecCGI
   AllowOverride None
   Order allow,deny
   Allow from all
   AuthName "Nagios Access"
   AuthType Basic
   AuthUSerFile /usr/local/etc/nagios/htpasswd.users
   Require valid-user

</Directory>

How do I resolve this issue?

Nagios Version: 4.3.4

Apache Version: 24

FreeBSD 11

Update 1:

I modified the directory index part in httpd.conf file to include index.php

<IfModule dir_module>
    DirectoryIndex index.html index.php
</IfModule>

And I see the following webpage

<?php
include_once(dirname(__FILE__).'/includes/utils.inc.php');
// Allow specifying main window URL for permalinks, etc.
$url = $cfg['cgi_base_url'].'/tac.cgi';

if ("yes" == "yes" && isset($_GET['corewindow'])) {

    // The default window url may have been overridden with a permalink...
    // Parse the URL and remove permalink option from base.
    $a = parse_url($_GET['corewindow']);

    // Build the base url.
    $url = htmlentities($a['path']).'?';
    $url = (isset($a['host'])) ? $a['scheme'].'://'.$a['host'].$url : '/'.$url;

    $query = isset($a['query']) ? $a['query'] : '';
    $pairs = explode('&', $query);
    foreach ($pairs as $pair) {
        $v = explode('=', $pair);
        if (is_array($v)) {
            $key = urlencode($v[0]);
            $val = urlencode(isset($v[1]) ? $v[1] : '');
            $url .= "&$key=$val";
        }
    }
    if (preg_match("/^http:\/\/|^https:\/\/|^\//", $url) != 1)
        $url = "main.php";
}

$this_year = '2017';
?>
<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Frameset//EN" "http://www.w3.org/TR/html4/frameset.dtd">

<html>
<head>
    <meta name="ROBOTS" content="NOINDEX, NOFOLLOW">
<script LANGUAGE="javascript">
    var n = Math.round(Math.random() * 10000000000);
    document.write("<title>Nagios Core on " + window.location.hostname + "</title>");
    document.cookie = "NagFormId=" + n.toString(16);
</script>
    <link rel="shortcut icon" href="images/favicon.ico" type="image/ico">
</head>

<frameset cols="180,*" style="border: 0px;">
    <frame src="side.php" name="side" frameborder="0" style="">
    <frame src="<?php echo $url; ?>" name="main" frameborder="0" style="">

    <noframes>
        <!-- This page requires a web browser which supports frames. -->
        <h2>Nagios Core</h2>
        <p align="center">
            <a href="https://www.nagios.org/">www.nagios.org</a><br>
            Copyright &copy; 2010-<?php echo $this_year; ?> Nagios Core Development Team and Community Contributors.
            Copyright &copy; 1999-2010 Ethan Galstad<br>
        </p>
        <p>
            <i>Note: These pages require a browser which supports frames</i>
        </p>
    </noframes>
</frameset>

</html>

But the error Cannot serve directory /usr/local/www/nagios/: No matching DirectoryIndex (index.html) found, and server-generated directory index forbidden by Options directive hasn't gone away.

Best Answer

So the directory index may be the issue here.

<IfModule dir_module>
    DirectoryIndex index.php index.html index.htm AddType application/x-httpd-php .phpAddType application/x-httpd-php-source .phps
</IfModule>

Full documentation is here: https://support.nagios.com/kb/article.php?id=96#FreeBSD