Help Processing a pl script pls
AMP Admin
admin at ampprod.com
Fri Jun 26 23:42:10 MSD 2009
I'm trying to get the "Easy PHP Version" for processing cgi-bin (http://wiki.nginx.org//NginxSimpleCGI) but I can't seem to get it right.
The following keeps returning 404. I know the file is there because when I remove the following it prompts me to download the file.
### CGI ###
location ~ ^/cgi-bin/.*\.(cgi|pl|py|rb) {
gzip off;
fastcgi_pass 127.0.0.1:9000;
fastcgi_index cgi-bin.php;
fastcgi_param SCRIPT_FILENAME /etc/nginx/cgi-bin.php;
fastcgi_param SCRIPT_NAME cgi-bin.php;
fastcgi_param X_SCRIPT_FILENAME /var/www/html/cgi-bin/awstats.pl;
fastcgi_param X_SCRIPT_NAME awstats.pl;
fastcgi_param QUERY_STRING $query_string;
fastcgi_param REQUEST_METHOD $request_method;
fastcgi_param CONTENT_TYPE $content_type;
fastcgi_param CONTENT_LENGTH $content_length;
fastcgi_param GATEWAY_INTERFACE CGI/1.1;
fastcgi_param SERVER_SOFTWARE nginx;
fastcgi_param REQUEST_URI $request_uri;
fastcgi_param DOCUMENT_URI $document_uri;
fastcgi_param DOCUMENT_ROOT $document_root;
fastcgi_param SERVER_PROTOCOL $server_protocol;
fastcgi_param REMOTE_ADDR $remote_addr;
fastcgi_param REMOTE_PORT $remote_port;
fastcgi_param SERVER_ADDR $server_addr;
fastcgi_param SERVER_PORT $server_port;
fastcgi_param SERVER_NAME $server_name;
fastcgi_param REMOTE_USER $remote_user;
}
### /CGI ###
I see this in the error log:
[error] 30432#0: *1 FastCGI sent in stderr: "PHP Notice: Undefined index: X_SCRIPT_FILENAME in /etc/nginx/cgi-bin.php on line 10
Here is cgi-bin.php:
<?php
$descriptorspec = array(
0 => array("pipe", "r"), // stdin is a pipe that the child will read from
1 => array("pipe", "w"), // stdout is a pipe that the child will write to
2 => array("pipe", "w") // stderr is a file to write to
);
$newenv = $_ENV;
$newenv["SCRIPT_FILENAME"] = $_ENV["X_SCRIPT_FILENAME"];
$newenv["SCRIPT_NAME"] = $_ENV["X_SCRIPT_NAME"];
if (is_executable($_ENV["X_SCRIPT_FILENAME"])) {
$process = proc_open($_ENV["X_SCRIPT_FILENAME"], $descriptorspec, $pipes, NULL, $newenv);
if (is_resource($process)) {
fclose($pipes[0]);
$head = fgets($pipes[1]);
while (strcmp($head, "\n")) {
header($head);
$head = fgets($pipes[1]);
}
fpassthru($pipes[1]);
fclose($pipes[1]);
fclose($pipes[2]);
$return_value = proc_close($process);
}
else {
header("Status: 500 Internal Server Error");
echo("Internal Server Error");
}
}
else {
header("Status: 404 Page Not Found");
echo("Page Not Found");
}
?>
More information about the nginx
mailing list