Archive

Posts Tagged ‘perl’

在Nginx下运行perl-cgi脚本

September 16th, 2009 Wei No 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: , , , , ,