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