使用nginx和Perl-FastCGI读取POST数据

使用nginx和Perl-FastCGI读取POST数据,perl,nginx,fastcgi,Perl,Nginx,Fastcgi,我正在用nginx建立一个网站,需要让它运行一些perl程序,所以我安装了FastCGI并将其全部设置好。我已将此添加到网站的配置中: location ~ \.pl$ { gzip off; include /etc/nginx/fastcgi_params; fastcgi_pass unix:/var/run/fcgiwrap.socket; fastcgi_index index.pl; fastcgi_param SCRIPT_FILENAME

我正在用nginx建立一个网站,需要让它运行一些perl程序,所以我安装了FastCGI并将其全部设置好。我已将此添加到网站的配置中:

location ~ \.pl$ {
    gzip off;
    include /etc/nginx/fastcgi_params;
    fastcgi_pass unix:/var/run/fcgiwrap.socket;
    fastcgi_index index.pl;
    fastcgi_param SCRIPT_FILENAME /[...]/www$fastcgi_script_name;
    fastcgi_param QUERY_STRING     $query_string;
}
然后我编写了一个test.pl程序:

#!/usr/bin/perl
print "Content-type:text/html\n\n";
print "Body here ";
print $#ARGV;

我得到的结果是“Body here-1”。因此,perl程序正在正确运行。现在我唯一的问题是,就我的一生而言,我找不到如何读取POST数据。如果这很棘手,我也找不到如何读取GET URL参数。这两种方法对我来说都足够了。

这比看上去要简单。下面是我使用的perl脚本

#!/usr/bin/perl 
use CGI;

print "Content-type:text/html\n\n";

my $q = CGI->new;
print "Your name is";
print $q->param("name");

就这样。它一点也不特定于nginx。

您可以
使用CGI
,但在大多数情况下,您需要一个真正的框架。没错,CGI的关键在于它是一个独立于平台的接口。但是现在强烈建议您使用一个完整的功能web框架来为您抽象这些细节。(现在我喜欢。)它有一个层,可以通过Plack.btw与nginx接口,不需要Plack与mojolicious+nginx。事实上,对于真正酷的实时功能,你并不想要它。更多信息,请参阅。