This module makes it possible to execute Perl directly within Nginx and call Perl via SSI.
Unless built at compile-time, the module is not available. The default is to not build this module. If you want to enable this module, is necessary to specify --with-http_perl_module when running configure.
Your system must have Perl 5.6.1 or above.
This module is experimental; therefore anything is possible and bugs are likely.
Example:
http {
perl_modules perl/lib;
perl_require hello.pm;
perl_set $msie6 '
sub {
my $r = shift;
my $ua = $r->header_in("User-Agent");
return "" if $ua =~ /Opera/;
return "1" if $ua =~ / MSIE [6-9] \.\d+/;
return "";
}
';
server {
location / {
perl hello::handler;
}
}
}
perl/lib/hello.pm:
package hello;
use nginx;
sub handler {
my $r = shift;
$r->send_http_header("text/html");
return OK if $r->header_only;
$r->print("hello!\n
");
$r->rflush;
if (-f $r->filename or -d _) {
$r->print($r->uri, " exists!\n");
}
return OK;
}
1;
__END__
syntax:*perl module::function | 'sub {...}'*
default:*no*
context:*location*
Directive establishes a function for the data location.
syntax:*perl_modules path*
default:*no*
context:*http*
Directive assigns additional path for Perl modules. Since version 0.6.7 this path is relative to directory of nginx configuration file nginx.conf, but not to nginx prefix directory.
syntax:*perl_require module*
default:*no*
context:*http*
There can be multiple perl_require directives.
syntax:*perl_set module::function | 'sub {...}'*
default:*no*
context:*http*
Directive establishes the function of variable ???
Instruction format is as follows:
Methods of request object $r:
package hello;
use nginx;
sub handler {
my $r = shift;
if ($r->request_method ne "POST") {
return DECLINED;
}
if ($r->has_request_body(hello::post)) {
return OK;
}
return 400;
}
sub post {
my $r = shift;
$r->send_http_header;
$r->print("request_body: \"", $r->request_body, "\"
");
$r->print("request_body_file: \"", $r->request_body_file, "\"
\n");
return OK;
}
1;
__END__
So that the body of the demand of client is guaranteed to remain in memory, it is necessary to limit its size with the aidof client_max_body_size and to assign sufficient size for the buffer using client_body_buffer_size.