ПРОЕКТЫ 


  АРХИВ 


Apache-Talk @lexa.ru 

Inet-Admins @info.east.ru 

Filmscanners @halftone.co.uk 

Security-alerts @yandex-team.ru 

nginx-ru @sysoev.ru 


  СТАТЬИ 


  ПЕРСОНАЛЬНОЕ 


  ПРОГРАММЫ 



ПИШИТЕ
ПИСЬМА












     АРХИВ :: nginx-ru
Nginx-ru mailing list archive (nginx-ru@sysoev.ru)

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

nagios + nginx + fcgi


  • To: nginx-ru@xxxxxxxxx
  • Subject: nagios + nginx + fcgi
  • From: "Dima Nelen" <dnelen@xxxxxxxxx>
  • Date: Mon, 15 Oct 2007 14:24:52 +0000
  • Dkim-signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=beta; h=domainkey-signature:received:received:message-id:date:from:to:subject:mime-version:content-type; bh=W3uwDoKuZvbAdEJFmgJDaxH8Y+4XFsh4T7JJoPZ47J8=; b=MQP/hkwlB2earkX5IUHsfZVTpiQ+qcrs7XF/e//mqG3t2Fs3VTC+ndUXuxiwgXileQJ4eOfTKzGE+XYwmahIq/FM3uonJzbzCIgbOL1cT2ZV0UsvcQK+mC/JmC/Z++NbofrnOPeOyp/uhqt9Kx1MOUodQK//XmpbVdtdfgH+nHA=
  • Domainkey-signature: a=rsa-sha1; c=nofws; d=gmail.com; s=beta; h=received:message-id:date:from:to:subject:mime-version:content-type; b=eS2YJg09mFCkoizWsTj7zT+ZIQzE+5iMAQlFnmZHOhZhGbMP0h6xd06XROXtrAkE+/mHVjUVVKyVh8SACV55EY4e42KSp7888a1bFtqAwlzqrDZtYkbRG0/fWmFXFUgmxhQGFldEp0Wf25LWwXbJvqlUk7WEv4Nlsi9LAEVZFSM=

добрый день,
вот решил отказаться от апача и поставить nagios под nginx. для cgi,
где-то на китайском сайте, нашел модуль для прикручивания cgi файлов,
как fastcgi. вроди всё хорошо работало, пока не дошло до post
запросов. подскажите куда копать, ну уж очень не хочется вешать апач (

* perl-cgi.pl - скрипт, который вешается в виде fcgi сервера

* Firefox, LiveHTTPHeaders
http://nagios.worldapp/nagios/cgi-bin/cmd.cgi



POST /nagios/cgi-bin/cmd.cgi HTTP/1.1

Host: nagios.worldapp

User-Agent: Mozilla/5.0 (X11; U; Linux i686; ru; rv:1.8.1.7)
Gecko/20071003 Firefox/2.0.0.7

Accept: 
text/xml,application/xml,application/xhtml+xml,text/html;q=0.9,text/plain;q=0.8,image/png,*/*;q=0.5

Accept-Language: ru-ru,ru;q=0.8,en-us;q=0.5,en;q=0.3

Accept-Encoding: gzip,deflate

Accept-Charset: windows-1251,utf-8;q=0.7,*;q=0.7

Keep-Alive: 300

Connection: keep-alive

Referer: 
http://nagios.worldapp/nagios/cgi-bin/cmd.cgi?cmd_typ=6&host=localhost&service=Total+Processes

Authorization: Basic ZGV4eDpkZWx0YQ==

Content-Type: application/x-www-form-urlencoded

Content-Length: 75

cmd_typ=6&cmd_mod=2&host=localhost&service=Total+Processes&btnSubmit=Commit


HTTP/1.x 502 Bad Gateway

Server: nginx/0.5.26

Date: Mon, 15 Oct 2007 14:20:01 GMT

Content-Type: text/html

Content-Length: 383

Connection: keep-alive



* nagios config - почти дефолтный

* конфиг nginx host:
    server {
        listen       80;
        server_name  nagios.worldapp;

        #charset koi8-r;

        access_log  /var/log/nginx/nagios.access.log  main;

        error_page   500 502 503 504  /50x.html;
        location = /50x.html {
            root   html;
        }

        location / {
                root   /usr/local/nagios/share;
                auth_basic              "Restricted";
                auth_basic_user_file    /usr/local/nagios/etc/htpasswd.user;
        }

        location ~ \.cgi$ {
                root /usr/local/nagios/sbin;
                rewrite ^/nagios/cgi-bin/(.*)\.cgi /$1.cgi break;
                fastcgi_index index.cgi;
                auth_basic              "Restricted";
                auth_basic_user_file    /usr/local/nagios/etc/htpasswd.user;

                fastcgi_pass    unix:/usr/local/nagios/var/run/fcgi/nagios.sock;

                fastcgi_param   SCRIPT_FILENAME
/usr/local/nagios/sbin$fastcgi_script_name;
                fastcgi_param   QUERY_STRING
$query_string;

                fastcgi_param   REMOTE_ADDR
    $remote_addr;
                fastcgi_param   REMOTE_PORT
    $remote_port;
                fastcgi_param   REQUEST_METHOD
$request_method;
                fastcgi_param   REQUEST_URI
    $request_uri;

                fastcgi_param  SCRIPT_NAME
   $fastcgi_script_name;
                fastcgi_param   SERVER_ADDR
    $server_addr;
                fastcgi_param   SERVER_NAME
    $server_name;
                fastcgi_param   SERVER_PORT
    $server_port;
                fastcgi_param   SERVER_PROTOCOL
$server_protocol;
                fastcgi_param   SERVER_SOFTWARE                        nginx;

                fastcgi_param   CONTENT_LENGTH
$content_length;
                fastcgi_param   CONTENT_TYPE
$content_type;
                fastcgi_param   GATEWAY_INTERFACE                CGI/1.0;
                fastcgi_param   HTTP_ACCEPT_ENCODING        gzip,deflate;
                fastcgi_param   HTTP_ACCEPT_LANGUAGE        en;
                #include        conf/fastcgi_params;
        }

    }



-- 
*#)
#!/usr/bin/perl

use FCGI;
#perl -MCPAN -e 'install FCGI'
use Socket;

#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 main {
        #$socket = FCGI::OpenSocket( ":3461", 10 ); #use IP sockets
        $socket = FCGI::OpenSocket( "/var/run/nagios.sock", 10 ); #use UNIX 
sockets - user running this script must have w access to the 'nginx' folder!!
        $request = FCGI::Request( \*STDIN, \*STDOUT, \*STDERR, \%ENV, $socket );
        if ($request) {request_loop()};
            FCGI::CloseSocket( $socket );
}

sub request_loop {
        while( $request->Accept() >= 0 ) {
            
           #processing any STDIN input from WebServer (for CGI-GET actions)
           $env = $request->GetEnvironment();
           $stdin_passthrough ='';
           $req_len = 0 + $ENV{CONTENT_LENGTH};
           if ($ENV{REQUEST_METHOD} eq 'GET'){
                $stdin_passthrough .= $ENV{'QUERY_STRING'};
            }

            #running the cgi app
            if ( (-x $ENV{SCRIPT_FILENAME}) &&  #can I execute this?
                 (-s $ENV{SCRIPT_FILENAME}) &&  #Is this file empty?
                 (-r $ENV{SCRIPT_FILENAME})     #can I read this file?
            ){
                #http://perldoc.perl.org/perlipc.html#Safe-Pipe-Opens
                open $cgi_app, '-|', $ENV{SCRIPT_FILENAME}, $stdin_passthrough 
or print("Content-type: text/plain\r\n\r\n"); print "Error: CGI app returned no 
output - Executing $ENV{SCRIPT_FILENAME} failed !\n";
                if ($cgi_app) {print <$cgi_app>; close $cgi_app;}
            } 
            else {
                print("Content-type: text/plain\r\n\r\n");
                print "Error: No such CGI app - $req_len  - 
$ENV{CONTENT_LENGTH} - $ENV{REQUEST_METHOD} - $ENV{SCRIPT_FILENAME} may not 
exist or is not executable by this process.\n";
            }

        }
}



 




Copyright © Lexa Software, 1996-2009.