Nagios is a great monitoring system which is also distributed as rpm package in some repositories.
All rpms , as far as I know , are preconfigured to be used with apache as a webserver.
I recently been using nginx on some linux servers in Amazon VPC because it’s very efficient and uses resources quite lightly, allowing more users for the same server.
I’d like to share my configuration to use amazon stock nginx, php-fpm and nagios rpm packages from amazon repositories, this should be also very easyly portable on CentOS/ RHEL 6 with epel and maybe rpmforge repos.
The tricky part in the installation is that the latest nagios uses both php and CGIs , they are usually handled by nginx as FastCGI applications.
There are a lot of possible implementations, I choose php-fpm (with php 5.4) for php pages and a perl fastcgi-wrapper.pl script I found mentioned here, here you can download the script.
First of all I yum installed nginx, php54-fpm , all php54* packages I needed, nagios, nagios-plugins-all , perl-FCGI
I configured php-fpm to use a unix socket in /etc/php-fpm.d/www.conf with :
listen = /tmp/phpfpm.sock
while my fastcgi wrapper in /usr/local/sbin/fastcgi-wrapper.pl contains an IP socket:
$socket = FCGI::OpenSocket( "127.0.0.1:8999", 10 ); #use IP sockets
You can start php-fpm as a service with service php-fpm start
While you can control the fastcgi-wrapper.pl script with upstart by placing the file /etc/init/fastcgi-wrapper.conf with this content
start on runlevel [2345] stop on runlevel [016] respawn exec /usr/bin/perl /usr/local/sbin/fastcgi-wrapper.pl
and issueing initctl start fastcgi-wrapper .
This is the nginx virtualhost in /etc/nginx/conf.d/mynagios.mydomain.conf
server { server_name mynagios.mydomain.com; root /usr/share/nagios/html; error_log /var/log/nginx/nagios.error.log ; access_log /var/log/nginx/nagios.access.log main; expires 31d; index index.php index.html; auth_basic "Restricted"; auth_basic_user_file /etc/nginx/htpasswd; location /nagios/stylesheets { alias /usr/share/nagios/html/stylesheets; } location /nagios/js { alias /usr/share/nagios/html/js; } location /nagios/images { alias /usr/share/nagios/html/images; } location ~ \.cgi$ { root /usr/lib64/nagios/cgi-bin; rewrite ^/cgi-bin/(.*)$ /$1; include /etc/nginx/fastcgi_params; fastcgi_param AUTH_USER $remote_user; fastcgi_param REMOTE_USER $remote_user; fastcgi_param SCRIPT_FILENAME /usr/lib64/$fastcgi_script_name; fastcgi_pass 127.0.0.1:8999; } location ~ \.php$ { fastcgi_split_path_info ^(.+\.php)(/.+)$; #NOTE: You should have "cgi.fix_pathinfo = 0;" in php.ini include fastcgi_params; fastcgi_param SCRIPT_FILENAME $document_root$fastcgi_script_name; fastcgi_intercept_errors on; fastcgi_pass unix:/tmp/phpfpm.sock; } }
As you can see the whole virtualhost is behind basic authentication.
Please let me know what you think of this, is there any better way to achieve the same?
Cheers
G.