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

时间:2022-10-27 22:38:40

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

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

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

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

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

我的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});
}
}
}

This is my code in my lighttpd config file:

这是我的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
))

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.

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

Thanks for any help!

谢谢你的帮助!

4 个解决方案

#1


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

您似乎没有发送正确的标头。使用CGI模块中的“标题”功能发出标题

$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

#2


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);
}

#3


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

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

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

static-file.exclude-extensions =(“。php”,“。pl”)

Or it will just download the file like any other.

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

#4


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.

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

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

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

Thanks again

#1


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

您似乎没有发送正确的标头。使用CGI模块中的“标题”功能发出标题

$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

#2


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);
}

#3


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

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

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

static-file.exclude-extensions =(“。php”,“。pl”)

Or it will just download the file like any other.

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

#4


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.

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

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

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

Thanks again