尝试使用 fast-cgi 和 lighttpd 运行 perl 脚本,但文件只是下载

发布于 2024-07-19 03:22:20 字数 1024 浏览 6 评论 0原文

问题是我的 .pl 脚本被下载为空白文件而不是被执行。

我读到: http://redmine.lighttpd.net/wiki/lighttpd/ApplicationsUsingLighttpd

我的dispatch.fcgi如下:(它位于usr/bin/

#!perl
#!/usr/bin/perl
use strict;
use CGI::Fast;
use Embed::Persistent; {
my $p = Embed::Persistent->new();
while (new CGI::Fast) {
my $filename = $ENV{SCRIPT_FILENAME};
my $package = $p->valid_package_name($filename);
my $mtime;
if ($p->cached($filename, $package, \$mtime)) {
eval {$package->handler;};
}
else {
$p->eval_file($ENV{SCRIPT_FILENAME});
}
}
}

这是我的lighttpd配置文件中的代码:

".pl" =>
((
"fastcgi.debug" => 1,
"bin-path" => "/usr/bin/dispatch.fcgi",
"socket" => "/tmp/fcgi.socket",
"check-local" => "disable",
"min-procs" => 1,
"max-procs" => 5,
"idle-timeout" => 20
))

我必须安装CGI.pm和嵌入的cpan模块。 现在我的服务器日志中没有收到任何错误,但正如我所说,脚本只是下载。

谢谢你的帮助!

The problem is my .pl script is downloaded as a blank file instead of being executed.

I read: http://redmine.lighttpd.net/wiki/lighttpd/ApplicationsUsingLighttpd

My dispatch.fcgi is the following: (it is located in usr/bin/

#!perl
#!/usr/bin/perl
use strict;
use CGI::Fast;
use Embed::Persistent; {
my $p = Embed::Persistent->new();
while (new CGI::Fast) {
my $filename = $ENV{SCRIPT_FILENAME};
my $package = $p->valid_package_name($filename);
my $mtime;
if ($p->cached($filename, $package, \$mtime)) {
eval {$package->handler;};
}
else {
$p->eval_file($ENV{SCRIPT_FILENAME});
}
}
}

This is my code in my lighttpd config file:

".pl" =>
((
"fastcgi.debug" => 1,
"bin-path" => "/usr/bin/dispatch.fcgi",
"socket" => "/tmp/fcgi.socket",
"check-local" => "disable",
"min-procs" => 1,
"max-procs" => 5,
"idle-timeout" => 20
))

I had to install CGI.pm and the cpan module embed.
Now I do not get any errors in my server log, but as I said, the script just downloads.

Thanks for any help!

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(4

归属感 2024-07-26 03:22:20

谢谢你!

#!/usr/bin/perl -w
use strict;
my $cgi = new CGI;
print $cgi->header();
print 'Hello world.';

作品! 但是,我想知道为什么我需要打印标头才能使其与 fastcgi 和 lighttpd 一起使用。 我有一个别人写的大脚本,可以在我的 apache 和常规 cgi 服务器上运行。 我想我必须修改它才能在我的新服务器上工作。

问题是我认为打印标题可能会弄乱脚本,因为它会执行类似打印执行的 html 之类的操作。

再次感谢

Thank you!

#!/usr/bin/perl -w
use strict;
my $cgi = new CGI;
print $cgi->header();
print 'Hello world.';

works! But, I am wondering why I need to print the headers to get it to work with fastcgi and lighttpd. I have a large script someone else wrote that works on my apache and regular cgi server. I guess I have to modify it to work on my new server.

The problem is I think printing the header might mess up the script because it does something like printing html that gets executed.

Thanks again

羁拥 2024-07-26 03:22:20

让 carp 写入文件并查找问题。

BEGIN {
use CGI::Carp qw/carpout/;
open LOG, ">>", "carp.log" or die("Cannot open file: $!\n");
carpout(LOG);
}

Have carp write to a file and look there for problems.

BEGIN {
use CGI::Carp qw/carpout/;
open LOG, ">>", "carp.log" or die("Cannot open file: $!\n");
carpout(LOG);
}
软甜啾 2024-07-26 03:22:20

确保为扩展设置静态排除。 像...

static-file.exclude-extensions = ( ".php", ".pl" )

或者它只会像其他文件一样下载该文件。

Make sure static exclude is set for the extensions. Something like...

static-file.exclude-extensions = ( ".php", ".pl" )

Or it will just download the file like any other.

兰花执着 2024-07-26 03:22:20

您似乎没有发送正确的标头。 使用 CGI 模块中的“header”函数来发出标头

$cgi = new CGI;
$cgi->header();

然后你就可以开始了。

有关更多信息,请查看标头文档:

http:// /cpansearch.perl.org/src/LDS/CGI.pm-3.43/cgi_docs.html#header

It appears that you are not sending the correct headers. Use the "header" function in the CGI module to emit the headers

$cgi = new CGI;
$cgi->header();

Then you should be good to go.

For more information check out the header documentation:

http://cpansearch.perl.org/src/LDS/CGI.pm-3.43/cgi_docs.html#header

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文