Page 1 of 2

Nagios apache web configuration

Posted: Tue Feb 24, 2015 7:50 pm
by nagiosuser22
Today I installed nagios core version 4.0.8 on a RHEL 6 machine. I followed the installation instructions at http://nagios.sourceforge.net/docs/nagi ... edora.html. However, when I try to access the website at http://localhost/nagios, I get the following error message:

You don't have permission to access /nagios/ on this server.

I investigated the issue and the file /etc/httpd/conf.d/nagios.conf contains:

# SAMPLE CONFIG SNIPPETS FOR APACHE WEB SERVER
#
# This file contains examples of entries that need
# to be incorporated into your Apache web server
# configuration file. Customize the paths, etc. as
# needed to fit your system.

ScriptAlias /nagios/cgi-bin "/usr/local/nagios/sbin"

<Directory "/usr/local/nagios/sbin">
# SSLRequireSSL
Options ExecCGI
AllowOverride None
Order allow,deny
Allow from all
# Order deny,allow
# Deny from all
# Allow from 127.0.0.1
AuthName "Nagios Access"
AuthType Basic
AuthUserFile /usr/local/nagios/etc/htpasswd.users
Require valid-user
</Directory>

Alias /nagios "/usr/local/nagios/share"

<Directory "/usr/local/nagios/share">
# SSLRequireSSL
Options None
AllowOverride None
Order allow,deny
Allow from all
# Order deny,allow
# Deny from all
# Allow from 127.0.0.1
AuthName "Nagios Access"
AuthType Basic
AuthUserFile /usr/local/nagios/etc/htpasswd.users
Require valid-user
</Directory>

If I change the Options line under the directory entry "/usr/local/nagios/share" to:
Options All

and run "service httpd restart", then I can access the website at http://localhost/nagios. However, the "Service Detail" navbar link mentioned at http://nagios.sourceforge.net/docs/nagi ... edora.html is missing. I just see a listing of files as seen in the attached screen shot. What am I doing wrong that I don't see the "Service Detail" navbar? What value should I have for the /nagios options line?

Thank you,
Peter

Re: Nagios apache web configuration

Posted: Wed Feb 25, 2015 8:59 am
by rhassing
Does the following file exist;

Code: Select all

 /usr/local/nagios/etc/htpasswd.users
Does it contain a user (nagiosadmin by default)?

Re: Nagios apache web configuration

Posted: Wed Feb 25, 2015 9:56 am
by jdalrymple
From step 5 on the URL you used:
Create a nagiosadmin account for logging into the Nagios web interface. Remember the password you assign to this account - you'll need it later.


htpasswd -c /usr/local/nagios/etc/htpasswd.users nagiosadmin
Looks like you might have just missed that step.

Re: Nagios apache web configuration

Posted: Wed Feb 25, 2015 11:25 am
by nagiosuser22
Thank you for the responses. However, the file /usr/local/nagios/etc/htpasswd.users did exist. Also, I think I had already run the following command before:

htpasswd -c /usr/local/nagios/etc/htpasswd.users nagiosadmin

Anyway, I ran this command again and restarted the apache web service with the command "service httpd restart". After doing that I still get the following message when trying to navigate to localhost/nagios

You don't have permission to access /nagios/ on this server.

If I change the following in /etc/httpd/conf.d/nagios.conf:

Alias /nagios "/usr/local/nagios/share"

<Directory "/usr/local/nagios/share">
# SSLRequireSSL
Options None
AllowOverride None
Order allow,deny
Allow from all
# Order deny,allow
# Deny from all
# Allow from 127.0.0.1
AuthName "Nagios Access"
AuthType Basic
AuthUserFile /usr/local/nagios/etc/htpasswd.users
Require valid-user
</Directory>

to:

Alias /nagios "/usr/local/nagios/share"

<Directory "/usr/local/nagios/share">
# SSLRequireSSL
Options All
AllowOverride None
Order allow,deny
Allow from all
# Order deny,allow
# Deny from all
# Allow from 127.0.0.1
AuthName "Nagios Access"
AuthType Basic
AuthUserFile /usr/local/nagios/etc/htpasswd.users
Require valid-user
</Directory>

Then I get the above screenshot which shows the files under /nagios with no "Service Detail" navbar.

What am I still doing wrong? Could there be something wrong in the Apache config file /etc/httpd/conf/httpd.conf? Could I have an option in there that is not set correctly? I have attached the apache main config file (/etc/httpd/conf/httpd.conf) and the Nagios Apache config file (/etc/httpd/conf.d/nagios.conf).

Re: Nagios apache web configuration

Posted: Wed Feb 25, 2015 11:49 am
by jdalrymple

Code: Select all

Options None
is proper

Code: Select all

Options All
is pretty bad for security:
http://httpd.apache.org/docs/2.2/mod/core.html#options

Can you tail your log access log when you're trying to load the Nagios Core home and show us the pertinent output?

Code: Select all

tail -f /etc/httpd/logs/access_log

Re: Nagios apache web configuration

Posted: Wed Feb 25, 2015 12:06 pm
by nagiosuser22
OK, I changed the settings in /etc/httpd/conf.d/nagios.conf for the nagios share back to:

Alias /nagios "/usr/local/nagios/share"

<Directory "/usr/local/nagios/share">
# SSLRequireSSL
Options None
AllowOverride None
Order allow,deny
Allow from all
# Order deny,allow
# Deny from all
# Allow from 127.0.0.1
AuthName "Nagios Access"
AuthType Basic
AuthUserFile /usr/local/nagios/etc/htpasswd.users
Require valid-user
</Directory>

Here is what is logged to /etc/httpd/logs/access_log when I try to access localhost/nagios:

::1 - nagiosadmin [25/Feb/2015:11:02:30 -0600] "GET /nagios/ HTTP/1.1" 403 285 "-" "Mozilla/5.0 (X11; Linux x86_64; rv:17.0) Gecko/20131023 Firefox/17.0"

Also, the following is logged to /etc/httpd/log/error_log:

[Wed Feb 25 11:02:30 2015] [error] [client ::1] Directory index forbidden by Options directive: /usr/local/nagios/share/

Thank you,
Peter

Re: Nagios apache web configuration

Posted: Wed Feb 25, 2015 12:12 pm
by jdalrymple
Please post the results of

Code: Select all

grep -Ri directoryindex /etc/httpd/*

Re: Nagios apache web configuration

Posted: Wed Feb 25, 2015 2:13 pm
by nagiosuser22
# grep -Ri directoryindex /etc/httpd/*
/etc/httpd/conf/httpd.conf:# DirectoryIndex: sets the file that Apache will serve if a directory
/etc/httpd/conf/httpd.conf:DirectoryIndex index.html index.html.var
Binary file /etc/httpd/modules/mod_dir.so matches

Thank you,
Peter

Re: Nagios apache web configuration

Posted: Wed Feb 25, 2015 2:27 pm
by jdalrymple
Looks like your php install didn't create the DirectoryIndex.

to fix your Nagios:

Code: Select all

echo "DirectoryIndex index.php" > /usr/local/nagios/share/.htaccess; chown apache /usr/local/nagios/share/.htaccess

Re: Nagios apache web configuration

Posted: Wed Feb 25, 2015 3:11 pm
by nagiosuser22
I ran those commands:

echo "DirectoryIndex index.php" > /usr/local/nagios/share/.htaccess
chown apache /usr/local/nagios/share/.htaccess

and

service httpd restart

but I still don't have access to

http://localhost/nagios/

Note that when I copied an index.html to /usr/local/nagios/share/ and then when I navigated to localhost/nagios, I saw what was on the index.html page.

Could it be that php is not enabled on my system somehow?