带有Nginx和FastCGI的Perl Web服务-无法读取参数 [英] Perl web serving with nginx and FastCGI - not able to read parameters

查看:82
本文介绍了带有Nginx和FastCGI的Perl Web服务-无法读取参数的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

关于如何使用FastCGI到CGI包装器以使用nginx服务Perl代码的教程很多.但是我自己可以轻松地使用Perl模块,因此不需要包装器.我正在尝试找出正确的方法来进行设置.这是我到目前为止的代码:

There are any number of tutorials out there on how to use FastCGI to CGI wrappers to serve Perl code using nginx. But I'm comfortable working with Perl modules myself, so I don't need the wrapper. I'm trying to figure out the right way to set this up. Here's the code I have so far:

#!perl

use CGI;
use FCGI;

my $s = FCGI::OpenSocket(':9000',20);
my $r = FCGI::Request( \*STDIN, \*STDOUT, \*STDERR,
    \%ENV, $s);
while ($r->Accept >= 0) {
    my $cgi = CGI->new;
    print "Content-type: text/html\n\n";
    print "<html><body>The foo input is ", $cgi->param('foo'), "</body></html>";
    $r->Finish;
}

并像这样在nginx中启用它:

And enable it in nginx like so:

location /foo {
    include /etc/nginx/fastcgi_params;
    fastcgi_pass  127.0.0.1:9000;
    fastcgi_index index.pl;
}

问题在于,无论我调用脚本多少次,param都会返回自启动程序以来第一次调用该脚本时传递的值.有更好的方法吗?我也对CGI.pm的替代品持开放态度.

The problem is that no matter how many times I call the script, param returns the same value that was passed the very first time it was called since starting the program. Is there a better way of doing this? I'm open to alternatives to CGI.pm as well.

推荐答案

CGI :: Fast 将为您处理大部分工作,包括设置守护程序.

CGI::Fast will handle most of the work for you, including setting up the daemon.

use CGI::Fast;

local $ENV{FCGI_SOCKET_PATH} = ":9000";
local $ENV{FCGI_LISTEN_QUEUE} = 20;

while ($q = CGI::Fast->new) {
    print $q->header;
    print "<html><body>The foo input is ", $cgi->param('foo'), "</body></html>";
}

另一种方法是 Nginx :: Simple ,它可以让您更好地控制cgi-script-as-daemon的行为.

An alternative is Nginx::Simple which gives you more control over the behavior of your cgi-script-as-daemon.

这篇关于带有Nginx和FastCGI的Perl Web服务-无法读取参数的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆