gpt4 book ai didi

使用 nginx 和 FastCGI 的 Perl Web 服务 - 无法读取参数

转载 作者:行者123 更新时间:2023-12-05 00:37:07 25 4
gpt4 key购买 nike

有很多关于如何使用 FastCGI 到 CGI 包装器来使用 nginx 提供 Perl 代码的教程。但是我自己使用 Perl 模块很舒服,所以我不需要包装器。我正在尝试找出正确的设置方法。这是我到目前为止的代码:

#!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 中启用它,如下所示:
location /foo {
include /etc/nginx/fastcgi_params;
fastcgi_pass 127.0.0.1:9000;
fastcgi_index index.pl;
}

问题是无论我调用多少次脚本, param返回与启动程序后第一次调用时传递的相同值。有没有更好的方法来做到这一点?我对 CGI.pm 的替代方案持开放态度也是。

最佳答案

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

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 的行为。

关于使用 nginx 和 FastCGI 的 Perl Web 服务 - 无法读取参数,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/7206323/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com