Home > Computer Science > 在Nginx下运行perl-cgi脚本

在Nginx下运行perl-cgi脚本

Sep 16th, 2009 22:26:37 Leave a comment Go to comments

把Web Server更换为Nginx后,发现BugZilla不能用了。打开网站显示403 Forbidden,想来是因为BugZilla使用Perl CGI运行的原因。查了Nginx为数不多的文档,发现Nginx不能像其他Web Server(例如Apache)那样直接运行perl-cgi的脚本。

试用几个不同的方法后,发现确实有方法可以比较简单的实现perl-cgi的功能:

首先下载一个Perl Wrapper,我把它另存为~/perl-fastcgi.pl。

修改perl-fastcgi.pl的属性,添加可执行权限。运行该文件,该脚本会创建一个/var/run/nginx/perl_cgi-dispatch.sock文件。

修改nginx的配置文件,在server section中添加:

location ~ \.cgi$ {
        root           /srv/www/domain.tld/public_html;
        fastcgi_pass    unix:/var/run/nginx/perl_cgi-dispatch.sock;
        fastcgi_index   index.cgi;
        fastcgi_param  SCRIPT_FILENAME  $document_root$fastcgi_script_name;
        include         fastcgi_params;
}

配置工作就此完成,重新启动nginx即可。

对于BugZilla,可能还需要运行http://domain.tld/testagent.cgi。

Categories: Computer Science Tags: , , , , ,
  1. RedChen
    March 15th, 2011 at 11:44 | #1

    Perl Wrapper能给我一个吗?
    我也安装bugzilla,但是不能运行cgi,可以运行pl,很奇怪,希望博主帮帮忙,谢谢了

  2. RedChen
    March 15th, 2011 at 11:47 | #2

    浏览器在解析cgi的时候,是直接给出源代码,而不是解析之后的结果

  3. March 15th, 2011 at 22:37 | #3

    我的方法可能有些过时了。现在可以这里:http://library.linode.com/web-servers/nginx/ 有相对官方的perl-cgi的方法。

  4. RedChen
    March 16th, 2011 at 17:59 | #4

    @Wei ,
    谢谢,不过还是有问题,我的(ubuntu server 10.04)输入 chown -R www-data:www-data /home/wwwroot/ 系统报错chown: `www-data:www-data’: invalid user

  5. March 16th, 2011 at 22:18 | #5

    这是说你的系统上没有www-data这个用户,你要确定一下你的nginx对应的用户,有些配置文件上是nobody。(我当时为了省事,继承了apache的用户,所以是www-data)

    总的原则是,目录的owner和nginx的启动用户是一样的(最起码是一个组的)

  1. August 9th, 2010 at 18:40 | #1