Nginx+nagios安装配置

[root@Nagios ~]# vi /etc/nginx/nginx.conf

    server {
listen ;
server_name localhost;
auth_basic "Nagios Access";
auth_basic_user_file /usr/local/nagios/passwd;
location / {
root /usr/local/nagios/share;
index index.html index.htm index.php;
} location ~ .*\.(php|php5)?$ {
root /usr/local/nagios/share;
fastcgi_pass 127.0.0.1:;
fastcgi_index index.php;
include fastcgi.conf;
} location /nagios {
alias /usr/local/nagios/share;
} location /cgi-bin/images {
alias /usr/local/nagios/share/images;
} location /cgi-bin/stylesheets {
alias /usr/local/nagios/share/stylesheets;
} location /cgi-bin {
alias /usr/local/nagios/sbin;
} location ~ .*\.(cgi|pl)?$ {
gzip off;
root /usr/local/nagios/sbin;
rewrite ^/nagios/cgi-bin/(.*)\.cgi /$.cgi break;
fastcgi_pass unix:/var/run/perl-fastcgi.sock;
fastcgi_param SCRIPT_FILENAME /usr/local/nagios/sbin$fastcgi_script_name;
fastcgi_index index.cgi;
fastcgi_param REMOTE_USER $remote_user;
fastcgi_param HTTP_ACCEPT_LANGUAGE en_US;
include fastcgi_params;
fastcgi_read_timeout ;
} location /nagiosql/ {
alias /usr/local/nagios/nagiosql;
}
} [root@Nagios ~]# echo -en 'nagios:'>/usr/local/nagios/share/passwd
[root@Nagios ~]# perl -e 'print crypt($ARGV[0], "nagios")' passwd >>/usr/local/nagios/share/passwd
# 安装 PHP php-fpm
[root@Nagios ~]# yum install -y php php-fpm
[root@Nagios ~]# /etc/init.d/php-fpm start
# 安装perl FCGI
[root@Nagios ~]# yum install -y perl-devel
[root@Nagios src]# wget http://www.cpan.org/modules/by-module/FCGI/FCGI-0.74.tar.gz
[root@Nagios src]# tar zxf FCGI-0.74.tar.gz
[root@Nagios src]# cd FCGI-0.74
[root@Nagios FCGI-0.74]# perl Makefile.PL
[root@Nagios FCGI-0.74]# make && make install [root@Nagios ~]# touch /usr/bin/fastcgi-wrapper.pl
[root@Nagios ~]# chmod /usr/bin/fastcgi-wrapper.pl
[root@Nagios ~]# vi /usr/bin/fastcgi-wrapper.pl
#!/usr/bin/perl use FCGI;
use Socket;
use POSIX qw(setsid); require 'syscall.ph'; &daemonize; #this keeps the program alive or something after exec'ing perl scripts
END() { } BEGIN() { }
*CORE::GLOBAL::exit = sub { die "fakeexit\nrc=".shift()."\n"; };
eval q{exit};
if ($@) {
exit unless $@ =~ /^fakeexit/;
}; &main; sub daemonize() {
chdir '/' or die "Can't chdir to /: $!";
defined(my $pid = fork) or die "Can't fork: $!";
exit if $pid;
setsid or die "Can't start a new session: $!";
umask ;
} sub main {
#$socket = FCGI::OpenSocket( "127.0.0.1:8999", ); #use IP sockets
$socket = FCGI::OpenSocket( "/var/run/perl-fastcgi.sock", );
$request = FCGI::Request( \*STDIN, \*STDOUT, \*STDERR, \%req_params, $socket );
if ($request) { request_loop()};
FCGI::CloseSocket( $socket );
} sub request_loop {
while( $request->Accept() >= ) { #processing any STDIN input from WebServer (for CGI-POST actions)
$stdin_passthrough ='';
$req_len = + $req_params{'CONTENT_LENGTH'};
if (($req_params{'REQUEST_METHOD'} eq 'POST') && ($req_len != ) ){
my $bytes_read = ;
while ($bytes_read < $req_len) {
my $data = '';
my $bytes = read(STDIN, $data, ($req_len - $bytes_read));
last if ($bytes == || !defined($bytes));
$stdin_passthrough .= $data;
$bytes_read += $bytes;
}
} #running the cgi app
if ( (-x $req_params{SCRIPT_FILENAME}) && #can I execute this?
(-s $req_params{SCRIPT_FILENAME}) && #Is this file empty?
(-r $req_params{SCRIPT_FILENAME}) #can I read this file?
){
pipe(CHILD_RD, PARENT_WR);
my $pid = open(KID_TO_READ, "-|");
unless(defined($pid)) {
print("Content-type: text/plain\r\n\r\n");
print "Error: CGI app returned no output - ";
print "Executing $req_params{SCRIPT_FILENAME} failed !\n";
next;
}
if ($pid > ) {
close(CHILD_RD);
print PARENT_WR $stdin_passthrough;
close(PARENT_WR); while(my $s = <KID_TO_READ>) { print $s; }
close KID_TO_READ;
waitpid($pid, );
} else {
foreach $key ( keys %req_params){
$ENV{$key} = $req_params{$key};
}
# cd to the script's local directory
if ($req_params{SCRIPT_FILENAME} =~ /^(.*)\/[^\/]+$/) {
chdir $;
} close(PARENT_WR);
close(STDIN);
#fcntl(CHILD_RD, F_DUPFD, );
syscall(&SYS_dup2, fileno(CHILD_RD), );
#open(STDIN, "<&CHILD_RD");
exec($req_params{SCRIPT_FILENAME});
die("exec failed");
}
}
else {
print("Content-type: text/plain\r\n\r\n");
print "Error: No such CGI app - $req_params{SCRIPT_FILENAME} may not ";
print "exist or is not executable by this process.\n";
} }
} [root@Nagios ~]# touch /etc/init.d/perl-fastcgi
[root@Nagios ~]# chmod /etc/init.d/perl-fastcgi
[root@Nagios ~]# vi /etc/init.d/perl-fastcgi
#!/bin/sh
#
# nginx – this script starts and stops the nginx daemon
#
# chkconfig: -
# description: Nginx is an HTTP(S) server, HTTP(S) reverse \
# proxy and IMAP/POP3 proxy server
# processname: nginx
# config: /opt/nginx/conf/nginx.conf
# pidfile: /opt/nginx/logs/nginx.pid # Source function library.
. /etc/rc.d/init.d/functions # Source networking configuration.
. /etc/sysconfig/network # Check that networking is up.
[ "$NETWORKING" = "no" ] && exit perlfastcgi="/usr/bin/fastcgi-wrapper.pl"
prog=$(basename perl) lockfile=/var/lock/subsys/perl-fastcgi start() {
[ -x $perlfastcgi ] || exit
echo -n $"Starting $prog: "
daemon $perlfastcgi
retval=$?
echo
[ $retval -eq ] && touch $lockfile
return $retval
} stop() {
echo -n $"Stopping $prog: "
killproc $prog -QUIT
retval=$?
echo
[ $retval -eq ] && rm -f $lockfile
return $retval
} restart() {
stop
start
} reload() {
echo -n $”Reloading $prog: ”
killproc $nginx -HUP
RETVAL=$?
echo
} force_reload() {
restart
}
rh_status() {
status $prog
} rh_status_q() {
rh_status >/dev/null >&
} case "$1" in
start)
rh_status_q && exit
$
;;
stop)
rh_status_q || exit
$
;;
restart)
$
;;
reload)
rh_status_q || exit
$
;;
force-reload)
force_reload
;;
status)
rh_status
;;
condrestart|try-restart)
rh_status_q || exit
;;
*)
echo $"Usage: $0 {start|stop|status|restart|condrestart|try-restart|reload|force-reload}"
exit
esac

nagios安装请参考该篇:http://www.cnblogs.com/caoguo/p/4981903.html

Nginx+nagios安装配置的更多相关文章

  1. nginx初级安装配置

    nginx初级安装配置 转自:(lykyl原创)http://www.cnblogs.com/lykyl/archive/2012/11/21/2781077.html 实验环境:系统 CENTOS5 ...

  2. nginx+tomcat安装配置

    nginx+tomcat安装配置 # nginx+tomcat安装配置 #创建网站目录 mkdir -p /www/wwwroot cd /www #安装配置 wget http://mirrors. ...

  3. gerrit+nginx+centos安装配置

    安装环境 centos 6.8 gerrit-full-2.5.2.war 下载地址:https://gerrit-releases.storage.googleapis.com/gerrit-ful ...

  4. Nginx的安装配置和tomcat负载均衡

    Nginx简介 什么是nginx? Nginx是一款高性能的http 服务器/反向代理服务器及电子邮件(IMAP/POP3)代理服务器.由俄罗斯的程序设计师Igor Sysoev所开发,官方测试ngi ...

  5. nginx php-fpm安装配置 CentOS编译安装php7.2

    CentOS编译安装php7.2 介绍: 久闻php7的速度以及性能那可是比php5系列的任何一版本都要快,具体性能有多好,建议还是先尝试下再说.如果你是升级或新安装,那你首先需要考虑php7和程序是 ...

  6. 吴裕雄--天生自然Django框架开发笔记:Django Nginx+uwsgi 安装配置

    Django Nginx+uwsgi 安装配置 使用 python manage.py runserver 来运行服务器.这只适用测试环境中使用. 正式发布的服务,需要一个可以稳定而持续的服务器,比如 ...

  7. centos 系统下安装FastDFS+nginx+fastdfs-nginx-module安装配置

    前言: 以前的项目上传的文件都是保存到本地或者是局域网内的共享文件夹下,由于数据量,服务器的负载均衡(分机的某些图片无法访问的问题处理)等因素的情况下,就想到用fastdfs来文件管理,花了几天时间硬 ...

  8. Nginx服务安装配置

    1.Nginx介绍 Nginx是一个高性能的HTTP和反向代理服务器,由俄罗斯人开发的,第一个版本发布于2004年10月4日.Nginx由于出色的性能,在世界范围内受到了越来越多人的关注,其特点是占有 ...

  9. Django Nginx+uwsgi 安装配置

    使用 python manage.py runserver 来运行服务器.这只适用测试环境中使用. 正式发布的服务,我们需要一个可以稳定而持续的服务器,比如apache, Nginx, lighttp ...

随机推荐

  1. android 日历

    [1].[代码] [Java]代码 跳至 [1] ? 1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 2 ...

  2. hdu5305(2015多校2)--Friends(状压,深搜)

    Friends Time Limit: 2000/1000 MS (Java/Others)    Memory Limit: 65536/65536 K (Java/Others) Total Su ...

  3. Oracle执行存储过程报错——ora-01031:权限不足

    执行DDL报错 在oracle存储过程中,默认是可以直接执行DML和DQL的,但是执行CREATE这种的DDL则需要借助EXECUTE IMMEDIATE 如: create or replace p ...

  4. Codeforces Round #273 (Div. 2)D. Red-Green Towers DP

    D. Red-Green Towers   There are r red and g green blocks for construction of the red-green tower. Re ...

  5. 从基于 SQL 的 CURD 操作转移到基于语义 Web 的 CURD 操作

    中文名称 CURD 含义 数据库技术中的缩写词 操作对象 一般的项目开发的各种参数 作用 用于处理数据的基本原子操作     它代表创建(Create).更新(Update).读取(Retrieve) ...

  6. Setup Script in SoapUI - 停止项目运行 (abort project)

    TestSuite需要依赖一个先决条件(比如Login) 当Login失败则立即停止Project运行 在Project的Setup Script的代码如下 import com.eviware.so ...

  7. HDU 5862Counting Intersections

    Counting Intersections Time Limit: 12000/6000 MS (Java/Others)    Memory Limit: 65536/65536 K (Java/ ...

  8. [POI 2007] Zap

    [题目链接] https://www.lydsy.com/JudgeOnline/problem.php?id=1101 [算法] 首先 , 问题可以转化为求GCD(x,y) = 1,x <= ...

  9. B1299 [LLH邀请赛]巧克力棒 博弈论

    这个题一看就是nim游戏的变形.每次先手取出巧克力就是新建一个nim,但假如先手取一个为0的而且无论后手怎么取剩下的都无法为零就行了.然后用dfs跑. 题干: Description TBL和X用巧克 ...

  10. ZOJ2334 Monkey King 左偏树

    ZOJ2334 用左偏树实现优先队列最大的好处就是两个队列合并可以在Logn时间内完成 用来维护优先队列森林非常好用. 左偏树代码的核心也是两棵树的合并! 代码有些细节需要注意. #include&l ...