upstream closed prematurely FastCGI stdout while reading response header from upstream

Alexander Skwar alexanders.mailinglists+nospam at gmail.com
Wed Dec 15 14:14:40 MSK 2010


Hi.

I'm trying to setup nginx 0.8.54 on a Solaris 10 system so, that it is able
to serve "normal" CGI scripts. I have read http://wiki.nginx.org/SimpleCGI
and tried to follow it - as it's not working, I guess I made some sort of
mistake…

When I check the access.log and error.log of nginx, I see the following when
a CGI script should be invoked ( http://nginx.pastebin.com/uY6PLbjU ):

==> access.log <==
10.0.1.49 - - [15/Dec/2010:11:17:48 +0100] "GET /cgi-bin/hw.cgi
HTTP/1.0" 502 383 "-" "Lynx/2.8.7rel.1 libwww-FM/2.14 SSL-MM/1.4.1
OpenSSL/0.9.8q" "-"

==> error.log <==
2010/12/15 11:17:48 [error] 28514#0: *3 upstream closed prematurely
FastCGI stdout while reading response header from upstream, client:
10.0.1.49, server: my.svr, request: "GET /cgi-bin/hw.cgi HTTP/1.0",
upstream: "fastcgi://unix:/var/opt/local/nginx/fastcgi_temp/perl_cgi-dispatch.sock:",
host: "my.svr"

And the client (lynx in the case above…) displays this output:
   The page you are looking for is temporarily unavailable.
   Please try again later.

In my nginx.conf (complete file at http://nginx.pastebin.com/QW9yWQGd ),
I've got:

[…]
http {
    server {
        listen       80;
        server_name  my.svr;
        location ~ ^/cgi-bin/.*\.cgi$ {
           root /data/www;
           gzip off;      #gzip makes scripts feel slower since they
have to complete before getting gzipped
           fastcgi_pass
unix:/var/opt/local/nginx/fastcgi_temp/perl_cgi-dispatch.sock;
           fastcgi_index index.cgi;
           fastcgi_param SCRIPT_FILENAME /data/www$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, finally, the handler "cgiwrap-fcgi.pl" is exactly the script from
the nginx wiki @ http://wiki.nginx.org/SimpleCGI

For now (while testing things), I start cgiwrap-fcgi.pl manually as
user "webservd". I see the following output on the terminal:

$ /opt/service/scripts/cgiwrap-fcgi.pl
FastCGI: manager (pid 17129): initialized
FastCGI: manager (pid 17129): server (pid 17130) started
FastCGI: server (pid 17130): initialized
FastCGI: manager (pid 17129): server (pid 17131) started
FastCGI: server (pid 17131): initialized

FastCGI: manager (pid 17129): server (pid 17130) exited with status 2304
FastCGI: manager (pid 17129): server (pid 17185) started
FastCGI: server (pid 17185): initialized

The last 3 lines got printed, when I ran "lynx -dump
http://my.svr/cgi-bin/hw.cgi".

$ ls -la /var/opt/local/nginx/fastcgi_temp
total 4
drwx------ 2 webservd webservd 3 Dec 15 11:58 .
drwxr-xr-x 8 webservd webservd 9 Dec 15 11:17 ..
srwxr-xr-x 1 webservd webservd 0 Dec 15 11:58 perl_cgi-dispatch.sock

nginx runs as user and group "webservd".

You can find all the links on: http://j.mp/bundles/alexs1977/5

Well, why does it not work? I "guess" that there is some sort of communication
going on between nginx and this fastcgi wrapper, because when I stop the
wrapper process, I get a different error message in error.log:

==> error.log <==
2010/12/15 12:03:01 [error] 28514#0: *7 connect() to
unix:/var/opt/local/nginx/fastcgi_temp/perl_cgi-dispatch.sock failed
(146: Connection refused) while connecting to upstream, client:
10.0.1.49, server: my.svr, request: "GET /cgi-bin/hw.cgi HTTP/1.0",
upstream: "fastcgi://unix:/var/opt/local/nginx/fastcgi_temp/perl_cgi-dispatch.sock:",
host: "my.svr"

The "hw.cgi" script has proper permissions:

-rwxr-xr-x 2 webservd webservd 93 2010-12-15 11:16 /data/www/cgi-bin/hw.cgi

If it doesn't (eg. if it's 0644), then I get the following output on
the "lynx term":
Error: No such CGI app - /data/www/cgi-bin/hw.cgi may not exist or is not execut
able by this process.

And I can run the hw.cgi script just fine:

$ /data/www/cgi-bin/hw.cgi
Content-type: text/html

<html><body>Hello, world.</body></html>

I'm out of ideas — what might be causing this problem?

Thanks a lot,

Alexander
--
↯    Lifestream (Twitter, Blog, …) ↣ http://alexs77.soup.io/     ↯
↯ Chat (Jabber/Google Talk) ↣ a.skwar at gmail.com , AIM: alexws77  ↯



More information about the nginx mailing list