nginx配置cgi-bin运行perl

Standard

系统装的是Gentoo
实际上在gentoo上面如果用apache的话那装nagios是相当方便的,但我就是想把nagios装在nginx上面没办法^_^

wget http://www.nginx.eu/nginx-fcgi/nginx-fcgi.txt
mv nginx-fcgi.txt nginx-fcgi.pl
mv nginx-fcgi.pl /usr/bin/
chmod 777 /usr/bin/nginx-fcgi.pl
 
perl -MCPAN -e shell
cpan> install FCGI
cpan> install IO::All
cpan> install Socket
 
nginx-fcgi.pl -l /tmp/nginx-fcgi.log -pid /tmp/nginx-fcgi.pid -S /tmp/nginx-fcgi.sock
chmod 777 /tmp/nginx-fcgi.*
 
vi /etc/nginx/vhosts/nagios.conf
server
{
  listen       80;
  server_name  nagios.yemaosheng.com;
  index index.php index.html index.htm;
  root  /usr/local/nagios/share;
  location ~ .*\.php?$
  {
    fastcgi_pass    127.0.0.1:9000;
    fastcgi_index   index.php;
    include fastcgi_params;
    fastcgi_param SCRIPT_FILENAME /usr/local/nagios/share$fastcgi_script_name;
  }
  location /nagios/
  {
    gzip off;
    alias /usr/local/nagios/share/;
    index index.html index.htm index.php;
  }
  location ~ \.cgi$ {
     rewrite ^/nagios/cgi-bin/(.*)\.cgi /$1.cgi break;
     fastcgi_pass unix:/tmp/nginx-fcgi.sock;
     fastcgi_index index.cgi;
     fastcgi_param SCRIPT_FILENAME /usr/local/nagios/sbin$fastcgi_script_name;
     fastcgi_param HTTP_ACCEPT_LANGUAGE en_US;
     include fastcgi_params;
  }
  location ~ \.pl$ {
     fastcgi_pass  unix:/tmp/nginx-fcgi.sock;
     fastcgi_index index.pl;
     fastcgi_param SCRIPT_FILENAME  /usr/local/nagios/sbin$fastcgi_script_name;
     include /etc/nginx/fastcgi_params;
  }
}

转载请注明出处: http://yemaosheng.com

13 thoughts on “nginx配置cgi-bin运行perl

    • 502 Bad Gateway 一般是fastcgi的问题
      增加了fastcgi的timeout时间试试
      也可能是cgi进程数不够用,执行时间长,或者是进程死掉
      google上此类问题很多

  1. 进程数开了20几个都是好好的!timeout这个应该不是!应为我跑别的php网页一点问题都没!我感激问题就出在跑cgi 上面那个nginx-fcgi.pl 好像开不开都没影响不起作用!

    • 用apache的htpasswd命令生成htpasswd文件,然后nginx配置如下例:
      location /nginx {
      stub_status on;
      access_log on;
      auth_basic “NginxStatus”;
      auth_basic_user_file /usr/local/etc/nginx/htpasswd;
      }

Leave a Reply to 叶茂盛 Cancel reply

Your email address will not be published. Required fields are marked *

This site uses Akismet to reduce spam. Learn how your comment data is processed.