# Upstream closed prematurely FastCGI stdout while reading response header from upstream

**URL:** <https://www.ruby-forum.com/t/upstream-closed-prematurely-fastcgi-stdout-while-reading-response-header-from-upstream/226152>\
**Category:** NGINX\
**Created:** [December 15, 2010, 12:16pm UTC](https://www.ruby-forum.com/t/upstream-closed-prematurely-fastcgi-stdout-while-reading-response-header-from-upstream/226152 "2010-12-15T12:16:09Z")\
**Posts on this page:** 1\
**Page:** 1

<div class="post-metadata">

**Author:** ![Alexander\_Skwar](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/a/85e7bf/32.png) [@Alexander\_Skwar](https://www.ruby-forum.com/u/Alexander_Skwar)\
**Post date:** [December 15, 2010, 12:16pm UTC](https://www.ruby-forum.com/t/upstream-closed-prematurely-fastcgi-stdout-while-reading-response-header-from-upstream/226152/1 "2010-12-15T12:16:09Z")

</div>

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](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](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](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](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](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](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

Hello, world.

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

Thanks a lot,

## Alexander

↯ Lifestream (Twitter, Blog, …) ↣ [http://alexs77.soup.io/](http://alexs77.soup.io/) ↯  
↯ Chat (Jabber/Google Talk) ↣ removed\_email\_address@domain.invalid , AIM: alexws77 ↯
