1,nagios install 參考官方
https://assets.nagios.com/downloads/nagioscore/docs/Installing_Nagios_Core_From_Source.pdf#_ga=1.136427443.2075387674.1488266439
上面只是參考,請自行安裝最新版本的nagios,并自行忽略掉Apache的配置,我們來配置nginx支持nagios。
2,理解什么是cgi。fastcgi。寫的非常棒。要多棒有多棒。
參考文章:http://www.cnblogs.com/skynet/p/4173450.html
3,上文理解了,就好辦了。我們的目的就是讓nginx支持執(zhí)行我們nagios下的cgi。nginx基于安全性等考慮不讓直接執(zhí)行cgi,但支持fastcgi,所以我們要用到一個fastcig的warp來封裝cgi
上面只是參考,請自行安裝最新版本的nagios,并自行忽略掉Apache的配置,我們來配置nginx支持nagios。
2,理解什么是cgi。fastcgi。寫的非常棒。要多棒有多棒。
參考文章:http://www.cnblogs.com/skynet/p/4173450.html
3,上文理解了,就好辦了。我們的目的就是讓nginx支持執(zhí)行我們nagios下的cgi。nginx基于安全性等考慮不讓直接執(zhí)行cgi,但支持fastcgi,所以我們要用到一個fastcig的warp來封裝cgi
github上開源的項(xiàng)目 fcgiwarp https://github.com/gnosek/fcgiwrap
如果aotoreconf執(zhí)行不了,請自行安裝autoreconf。
然后就是怎么使用fcgiwarp ,作者提到了2種使用方法(針對這2種方法在nginx配置稍微不同):
第1種是作者自己寫的perl 的啟動器:作者說在他的主頁呢。。。。copy一下放在下面
我們把這個文件保存成 /etc/init.d/fcgiwrap 做成服務(wù)執(zhí)行即可。
第二種方法是用fastcgi的進(jìn)程管理器來啟動。
還是GitHub上開源的牛逼項(xiàng)目spawn-fcgi https://github.com/lighttpd/spawn-fcgi
我們寫一個啟動腳本
最后貼一個nginx簡單的配置。
git clone https://github.com/gnosek/fcgiwrap.git
autoreconf -i
./configure
make
make instal
ps:autoreconf -i
./configure
make
make instal
如果aotoreconf執(zhí)行不了,請自行安裝autoreconf。
然后就是怎么使用fcgiwarp ,作者提到了2種使用方法(針對這2種方法在nginx配置稍微不同):
usage
Most probably you will want fcgiwrap be launched by www-servers/spawn-fcgi. Or you could use the author's Perl launcher - see the homepage for that.
Most probably you will want fcgiwrap be launched by www-servers/spawn-fcgi. Or you could use the author's Perl launcher - see the homepage for that.
第1種是作者自己寫的perl 的啟動器:作者說在他的主頁呢。。。。copy一下放在下面
#!/usr/bin/perl
use strict;
use warnings FATAL => qw( all );
use IO::Socket::UNIX;
my $bin_path = '/usr/local/bin/fcgiwrap';
my $socket_path = $ARGV[0] || '/tmp/cgi.sock';
my $num_children = $ARGV[1] || 1;
close STDIN;
unlink $socket_path;
my $socket = IO::Socket::UNIX->new(
Local => $socket_path,
Listen => 100,
);
die "Cannot create socket at $socket_path: $!\n" unless $socket;
for (1 .. $num_children) {
my $pid = fork;
die "Cannot fork: $!" unless defined $pid;
next if $pid;
exec $bin_path;
die "Failed to exec $bin_path: $!\n";
}
use strict;
use warnings FATAL => qw( all );
use IO::Socket::UNIX;
my $bin_path = '/usr/local/bin/fcgiwrap';
my $socket_path = $ARGV[0] || '/tmp/cgi.sock';
my $num_children = $ARGV[1] || 1;
close STDIN;
unlink $socket_path;
my $socket = IO::Socket::UNIX->new(
Local => $socket_path,
Listen => 100,
);
die "Cannot create socket at $socket_path: $!\n" unless $socket;
for (1 .. $num_children) {
my $pid = fork;
die "Cannot fork: $!" unless defined $pid;
next if $pid;
exec $bin_path;
die "Failed to exec $bin_path: $!\n";
}
我們把這個文件保存成 /etc/init.d/fcgiwrap 做成服務(wù)執(zhí)行即可。
第二種方法是用fastcgi的進(jìn)程管理器來啟動。
還是GitHub上開源的牛逼項(xiàng)目spawn-fcgi https://github.com/lighttpd/spawn-fcgi
我們寫一個啟動腳本
spawn-fcgi -f /usr/local/sbin/fcgiwrap -p 9009 這個端口自己根據(jù)機(jī)器的端口使用情況自己來寫
最后貼一個nginx簡單的配置。
vim /etc/nginx/conf.d/nagios.conf #根據(jù)自己的nginx啟動位置自行調(diào)整
server {
server_name nagios.tony.com; #自己的域名
access_log /var/log/nginx/nagios-access.log;
error_log /var/log/nginx/nagios-error.log; #日志位置,發(fā)現(xiàn)nagios不能在瀏覽器展示,請看日志,看日志,
# auth_basic "Private";
# auth_basic_user_file /etc/nagios/htpasswd.users; #把認(rèn)證先去掉。跑起來在說在。 要把 /usr/local/nagios/etc/cgi.cfg 中的use_ssl_authentication=0
root /usr/local/nagios/share; #/usr/local/nagios nagios安裝目錄
index index.php index.html;
#php 的配置,請自行去解決。
location ~ \.php$ {
include /etc/nginx/fastcgi_params;
fastcgi_pass 127.0.0.1:9000; #php-fpm
fastcgi_index index.php;
fastcgi_param SCRIPT_FILENAME $document_root/$fastcgi_script_name;
}
location /nagios {
alias /usr/local/nagios/share;
}
location ~ \.cgi$ {
root /usr/local/nagios/sbin;
rewrite ^/nagios/cgi-bin/(.*)\.cgi /$1.cgi break;
include /etc/nginx/fastcgi_params;
fastcgi_param AUTH_USER $remote_user;
fastcgi_param REMOTE_USER $remote_user;
fastcgi_param SCRIPT_FILENAME /usr/local/nagios/sbin/$fastcgi_script_name;
fastcgi_pass unix:/tmp/cgi.sock; #這是上面第一種方式的配置。
#fastcgi_pass 127.0.0.1:9009; #這是上面第二種方式的配置。
}
}
server_name nagios.tony.com; #自己的域名
access_log /var/log/nginx/nagios-access.log;
error_log /var/log/nginx/nagios-error.log; #日志位置,發(fā)現(xiàn)nagios不能在瀏覽器展示,請看日志,看日志,
# auth_basic "Private";
# auth_basic_user_file /etc/nagios/htpasswd.users; #把認(rèn)證先去掉。跑起來在說在。 要把 /usr/local/nagios/etc/cgi.cfg 中的use_ssl_authentication=0
root /usr/local/nagios/share; #/usr/local/nagios nagios安裝目錄
index index.php index.html;
#php 的配置,請自行去解決。
location ~ \.php$ {
include /etc/nginx/fastcgi_params;
fastcgi_pass 127.0.0.1:9000; #php-fpm
fastcgi_index index.php;
fastcgi_param SCRIPT_FILENAME $document_root/$fastcgi_script_name;
}
location /nagios {
alias /usr/local/nagios/share;
}
location ~ \.cgi$ {
root /usr/local/nagios/sbin;
rewrite ^/nagios/cgi-bin/(.*)\.cgi /$1.cgi break;
include /etc/nginx/fastcgi_params;
fastcgi_param AUTH_USER $remote_user;
fastcgi_param REMOTE_USER $remote_user;
fastcgi_param SCRIPT_FILENAME /usr/local/nagios/sbin/$fastcgi_script_name;
fastcgi_pass unix:/tmp/cgi.sock; #這是上面第一種方式的配置。
#fastcgi_pass 127.0.0.1:9009; #這是上面第二種方式的配置。
}
}