perl fastcgi buffering problem

Stefan Parvu sparvu at systemdatarecorder.org
Sun Mar 14 20:50:38 MSK 2010


Hi,

Im trying to see how certain Perl CGI scripts will
work on nginx. Im using nginx stable on Solaris 10 
x86. 

My configuration:

Perl CGI support: nginx-fcgi-0.4.3
http://www.nginx.eu/nginx-fcgi.html

nginx.conf:

location ~ ^/cgi-bin/.*\.cgi$ {
            gzip off;
            fastcgi_pass    unix:/opt/sdr/report/ws/fastcgi_temp/nginx-fcgi.sock;
            fastcgi_read_timeout    5m;
            fastcgi_index    index.cgi;
            fastcgi_buffers  8  4k;
            fastcgi_max_temp_file_size 0;
            #
            #  You may copy and paste the lines under or use include directive
            #  include  /etc/nginx/nginx-fcgi.conf;
            #  In this example all is in one file 
            #
            fastcgi_param    SCRIPT_FILENAME  /opt/sdr/report/docroot/$fastcgi_script_name;
            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    SCRIPT_NAME  $fastcgi_script_name;
            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;
        }


and a simple script which should output the stdout to browser:

##############################################################
use strict;

print "$ENV{SERVER_PROTOCOL} 200 OK\n";
print "Server: $ENV{SERVER_SOFTWARE}\n";
print "Content-type: text/plain\n\n";

print "Starting for...\n";
$|=1;

for (my $i = 1; $i <= 5; $i++) {
    print "Iteration: $i\n";
    sleep 1;
}

print "All done\n";

This example uses non-parsed headers, like old days for Apache < 1.x where 
the server buffered the output of std CGI scripts. Passing:

print "$ENV{SERVER_PROTOCOL} 200 OK\n";
print "Server: $ENV{SERVER_SOFTWARE}\n";


should output directly to the browser the results, but it does not. 
Found out about: fastcgi_max_temp_file_size but that did not help.

Any ideas how can I see immediately the results from a simple CGI 
script in nginx/fcgi ?

thanks,
Stefan



More information about the nginx mailing list