# 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/191266>\
**Category:** NGINX\
**Created:** [July 8, 2010, 2:35pm UTC](https://www.ruby-forum.com/t/upstream-closed-prematurely-fastcgi-stdout-while-reading-response-header-from-upstream/191266 "2010-07-08T14:35:58Z")\
**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:** [July 8, 2010, 2:35pm UTC](https://www.ruby-forum.com/t/upstream-closed-prematurely-fastcgi-stdout-while-reading-response-header-from-upstream/191266/1 "2010-07-08T14:35:58Z")

</div>

Hello.

I’m trying to setup nginx 0.8.29 on an internal Solaris 10 system, so  
that it can  
serve simple CGI scripts. I read [http://wiki.nginx.org/NginxSimpleCGI](http://wiki.nginx.org/NginxSimpleCGI)  
and I’m trying  
to follow this setup.

When I try to exec a cgi script (by running eg. “wget  
[http://rpe-wgs.win.ch.da.rtr/RACE-CGI/test.cgi](http://rpe-wgs.win.ch.da.rtr/RACE-CGI/test.cgi)”),  
wget client prints “ERROR 502: Bad Gateway.” and in the nginx logs,  
there’s this:

==\> /var/opt/local/nginx/logs/access.log \<==  
10.0.4.20 - - [08/Jul/2010:13:48:28 +0200] “GET /RACE-CGI/test.cgi  
HTTP/1.0” 502 383 “-” “Wget/1.12 (linux-gnu)” “-”

==\> /var/opt/local/nginx/logs/error.log \<==  
2010/07/08 13:48:28 [error] 16479#0: \*40 upstream closed prematurely  
FastCGI stdout while reading response header from upstream, client:  
10.0.4.20, server: rpe-wgs.win.ch.da.rtr, request: “GET  
/RACE-CGI/test.cgi HTTP/1.0”, upstream:  
“fastcgi://unix:/var/opt/local/nginx/fastcgi\_temp/cgiwrap-dispatch.sock:”,  
host: “rpe-wgs.win.ch.da.rtr”

You can find the test.cgi on [http://paste.pocoo.org/show/234959/](http://paste.pocoo.org/show/234959/). I’m  
rather sure, that  
test.cgi did NOT get executed at all; reason: in the test.cgi shell  
script, there’s a command  
“mkdir -p /tmp/testcgi”. This command gets executed all the time, if  
the script get executed.  
But there’s no /tmp/testcgi directory on my server and the permissions  
of /tmp are  
good (ie. 1777); permissions of test.cgi are also good: 0755.

In my nginx.conf, there’s this (complete file at  
[http://paste.pocoo.org/show/234957/](http://paste.pocoo.org/show/234957/)):

```
    location ~ ^/RACE-CGI/.*\.cgi$ {
        gzip off;
        fastcgi_pass

```

unix:/var/opt/local/nginx/fastcgi\_temp/cgiwrap-dispatch.sock;  
fastcgi\_index index.cgi;

```
        fastcgi_param SCRIPT_FILENAME 

```

/opt/service/$fastcgi\_script\_name;  
include fastcgi\_params;  
}

The socket /var/opt/local/nginx/fastcgi\_temp/cgiwrap-dispatch.sock  
exists:

$ sudo ls -la /var/opt/local/nginx/fastcgi\_temp/  
total 4  
drwx------ 2 webservd webservd 3 2010-07-08 13:48 .  
drwxr-xr-x 6 webservd webservd 7 2010-07-08 11:39 …  
srwxr-xr-x 1 webservd webservd 0 2010-07-08 13:48 cgiwrap-dispatch.sock

(Changing the fastcgi\_temp directory to 0777 didn’t change anything.)

The socket gets created by the cgiwrap-fcgi.pl script, which is  
basically the same  
one as on [http://wiki.nginx.org/NginxSimpleCGI](http://wiki.nginx.org/NginxSimpleCGI); my version:  
[http://paste.pocoo.org/show/234956/](http://paste.pocoo.org/show/234956/)  
Those cgiwrap-fcgi.pl processes ARE running:

$ ps -ef | grep -v grep | grep -i cgiwrap | sort -k 4  
webservd 21561 14891 0 13:48:15 ? 0:00 sh -c  
/opt/service/scripts/cgiwrap-fcgi.pl  
/var/opt/local/nginx/fastcgi\_temp/cg  
webservd 21563 21561 0 13:48:15 ? 0:00 /opt/csw/bin/perl  
/opt/service/scripts/cgiwrap-fcgi.pl /var/opt/local/nginx/fas  
webservd 21670 21563 0 13:48:28 ? 0:00 /opt/csw/bin/perl  
/opt/service/scripts/cgiwrap-fcgi.pl /var/opt/local/nginx/fas  
webservd 1791 21563 0 14:09:47 ? 0:00 /opt/csw/bin/perl  
/opt/service/scripts/cgiwrap-fcgi.pl /var/opt/local/nginx/fas  
webservd 1814 21563 0 14:09:51 ? 0:00 /opt/csw/bin/perl  
/opt/service/scripts/cgiwrap-fcgi.pl /var/opt/local/nginx/fas  
webservd 4712 21563 0 14:15:17 ? 0:00 /opt/csw/bin/perl  
/opt/service/scripts/cgiwrap-fcgi.pl /var/opt/local/nginx/fas

They get cgiwrap-fcgi.pl gets executed by  
/etc/svc/method/svc-RTRcgi-fastcgi,  
which I run as user webservd. svc-RTRcgi-fastcgi is online at  
[http://paste.pocoo.org/show/234955/](http://paste.pocoo.org/show/234955/)

Here are all the URLs again:

svc-RTRcgi-fastcgi â†’ [http://paste.pocoo.org/show/234955/](http://paste.pocoo.org/show/234955/)  
cgiwrap-fcgi.pl â†’ [http://paste.pocoo.org/show/234956/](http://paste.pocoo.org/show/234956/)  
nginx.conf â†’ [http://paste.pocoo.org/show/234957/](http://paste.pocoo.org/show/234957/)  
fastcgi\_params â†’ [http://paste.pocoo.org/show/234958/](http://paste.pocoo.org/show/234958/)  
test.cgi â†’ [http://paste.pocoo.org/show/234959/](http://paste.pocoo.org/show/234959/)

What’s broken? What did I miss to do?

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 Â â†¯
