私はperl上にfastcgiを備えたlighttpdサーバーを持っています。Lighttpd 構成:
server.modules = (
"mod_access",
"mod_alias",
"mod_compress",
"mod_redirect",
"mod_rewrite",
"mod_accesslog",
)
server.document-root = "/var/www"
server.upload-dirs = ( "/var/cache/lighttpd/uploads" )
server.errorlog = "/var/log/lighttpd/error.log"
server.pid-file = "/var/run/lighttpd.pid"
server.username = "www-data"
server.groupname = "www-data"
server.max-keep-alive-requests = 10
server.max-keep-alive-idle = 5
#server.max-fds = 10240
server.max-connections = 8192
index-file.names = ( "index.php", "index.html",
"index.htm", "default.htm",
"index.lighttpd.html" )
url.access-deny = ( "~", ".inc" )
static-file.exclude-extensions = ( ".php", ".pl", ".fcgi" )
dir-listing.encoding = "utf-8"
server.dir-listing = "disable"
compress.cache-dir = "/var/cache/lighttpd/compress/"
compress.filetype = ( "application/x-javascript", "text/css", "text/html", "text/plain" )
include_shell "/usr/share/lighttpd/create-mime.assign.pl"
include_shell "/usr/share/lighttpd/include-conf-enabled.pl"
$HTTP["host"] =~ "(^|\.)hostname\.net$" {
server.document-root = "/var/www/hostname.net"
url.rewrite-once = (
"^/index.php" => "/index.pl",
)
}
高速 CGI が有効になっています。ここで構成fcgi.server:
fastcgi.server += ( ".pl" =>
((
"socket" => "/tmp/perl.socket" + var.PID,
"bin-path" => "/usr/bin/dispatch.fcgi",
"docroot" => "/var/www/hostname.net",
"check-local" => "disable",
))
)
ディスパッチ.fcgi:
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});
}
}
}
そして、これが私のスクリプトです(編集後):
use strict;
use warnings;
use CGI;
my $q = new CGI;
open my $fh, '>', "/var/www/hostname.net/payload.body" or die "Can't open payload.body: $!";
{
local $/;
print $fh $q->param('arg1');
}
close $fh;
print $q->header;
print $q->param('arg1');
リクエストを送信:
wget --post-data="arg1=dfsdfasf&arg2=sdfasfdsdf" http://hostname.net/test.pl --save-headers --quiet -O -
payload.body は空です (ただし、変更の時間は更新されます)。ダンプは次のとおりです。
HTTP/1.0 200 OK
Content-Type: text/html; charset=ISO-8859-1
Content-Length: 0
Connection: keep-alive
Date: Fri, 05 Oct 2012 12:23:07 GMT
Server: lighttpd/1.4.28
それで全部です。
この方法で POST パラメータを取得しようとしましたが、クエリが空になります。私はこのように試しました:
use Data::Dumper;
my $request;
use FCGI;
my $env;
my $q = FCGI::Request();
$env = $q->GetEnvironment();
my $buffer = "data\n";
if ( $ENV{'REQUEST_METHOD'} eq "POST" ){
read(STDIN, $buffer, $ENV{'CONTENT_LENGTH'});
}
else {
print ("some error");
};
print("Content-type: text/plain\r\n\r\n", Dumper($buffer),"\n");
リクエストから POST パラメーターを取得する必要があります (バイナリ投稿データ)。
手伝って頂けますか?多分私は間違った方法でポストパラメータを取りますか?
どうもありがとう!