# Nginx-FastCGI-C++

**URL:** <https://www.ruby-forum.com/t/nginx-fastcgi-c/200322>\
**Category:** NGINX\
**Created:** [December 9, 2010, 9:25am UTC](https://www.ruby-forum.com/t/nginx-fastcgi-c/200322 "2010-12-09T09:25:56Z")\
**Posts on this page:** 3\
**Page:** 1

<div class="post-metadata">

**Author:** ![Dobai-Pataky\_BSSSSl](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/d/77aa72/32.png) [@Dobai-Pataky\_BSSSSl](https://www.ruby-forum.com/u/Dobai-Pataky_BSSSSl)\
**Post date:** [December 9, 2010, 9:25am UTC](https://www.ruby-forum.com/t/nginx-fastcgi-c/200322/1 "2010-12-09T09:25:56Z")

</div>

I have a Fastcgi C++ program as follow:

```auto
1 #include "fcgi_stdio.h"
  2 #include
  3
  4 int main(void)
  5 {
  6 int count = 0;
  7 while(FCGI_Accept() >= 0)
  8 printf("Content-type: text/html\r\n"
  9 "\r\n"
 10 "Tiny3"
 11 "FastCGI World!"
 12 "Request number %d running on host %s\n",
 13 ++count, getenv("SERVER_NAME"));
 14 return 1;
 15 }
```

then i have modified the Nginx conf file

```auto
30 upstream fastcgiends{
31 server 127.0.0.1:9110 weight=1 max_fails=2 fail_timeout=30s;

32 server 127.0.0.1:9111 weight=1 max_fails=2 fail_timeout=30s;

33 }
```

```auto
location =/3.cgi {
             #fastcgi_pass 127.0.0.1:9553;
             fastcgi_pass fastcgiends;
       }
```

start the spawn-fcgi command :

```auto
spawn-fcgi -a 127.0.0.1 -p 9110 -f ./tiny3 -P ./pid/fastcgi_9110.pid
spawn-fcgi -a 127.0.0.1 -p 9111 -f ./tiny3 -P ./pid/fastcgi_9111.pid
```

but I found i can’t query it from the web `
http://122.36.180.89:9095/3.cgi
`

and does anyone konw sth about this problem ?

Posted at Nginx Forum:

> **[Nginx-FastCGI-C++](https://forum.nginx.org/read.php?2,157079,157079#msg-157079)**
>
> I have a Fastcgi C++ program as follow: \[code\] 1 #include "fcgi\_stdio.h" 2 #include \<stdlib.h\> 3 4 int main(void) 5 { 6 int count = 0; 7 while(FCGI\_Accept() \>= 0) 8 printf(&quot

---

<div class="post-metadata">

**Author:** ![kevinew](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/k/53a042/32.png) [@kevinew](https://www.ruby-forum.com/u/kevinew)\
**Post date:** [December 9, 2010, 11:23am UTC](https://www.ruby-forum.com/t/nginx-fastcgi-c/200322/2 "2010-12-09T11:23:25Z")

</div>

sorry，just add 2 lines is OK. have fixed it.

```auto
location =/3.cgi
 99 {
100 #fastcgi_pass 127.0.0.1:9110;
101 fastcgi_pass fastcgiends;
102 #proxy_pass http://fastcgiends;
103
104 fastcgi_param SCRIPT_FILENAME
/scripts$fastcgi_script_name;
105 include fastcgi_params;
106 }
```

Posted at Nginx Forum:

> **[Re: Nginx-FastCGI-C++](https://forum.nginx.org/read.php?2,157079,157112#msg-157112)**
>
> I have a Fastcgi C++ program as follow: \[code\] 1 #include "fcgi\_stdio.h" 2 #include \<stdlib.h\> 3 4 int main(void) 5 { 6 int count = 0; 7 while(FCGI\_Accept() \>= 0) 8 printf(&quot

---

<div class="post-metadata">

**Author:** ![kevinew](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/k/53a042/32.png) [@kevinew](https://www.ruby-forum.com/u/kevinew)\
**Post date:** [December 9, 2010, 11:44pm UTC](https://www.ruby-forum.com/t/nginx-fastcgi-c/200322/3 "2010-12-09T23:44:57Z")

</div>

You should use:  
fastcgi\_param SCRIPT\_FILENAME $document\_root$fastcgi\_script\_name;

Or even better:

`location = /3.cgi {
  fastcgi_pass fastcgiends;
  include fastcgi.conf;
}`

Posted at Nginx Forum:

> **[Re: Nginx-FastCGI-C++](https://forum.nginx.org/read.php?2,157079,157324#msg-157324)**
>
> I have a Fastcgi C++ program as follow: \[code\] 1 #include "fcgi\_stdio.h" 2 #include \<stdlib.h\> 3 4 int main(void) 5 { 6 int count = 0; 7 while(FCGI\_Accept() \>= 0) 8 printf(&quot
