# Configuratioin fastcgi C/C++ program

**URL:** <https://www.ruby-forum.com/t/configuratioin-fastcgi-c-c-program/189498>\
**Category:** NGINX\
**Created:** [June 1, 2010, 9:32pm UTC](https://www.ruby-forum.com/t/configuratioin-fastcgi-c-c-program/189498 "2010-06-01T21:32:44Z")\
**Posts on this page:** 7\
**Page:** 1

<div class="post-metadata">

**Author:** ![JCR](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/j/258eb7/32.png) [@JCR](https://www.ruby-forum.com/u/JCR)\
**Post date:** [June 1, 2010, 9:32pm UTC](https://www.ruby-forum.com/t/configuratioin-fastcgi-c-c-program/189498/1 "2010-06-01T21:32:44Z")

</div>

hello

I have a fastcgi program like this

```auto
      1 #include "/usr/local/include/fcgi_stdio.h"
      2 #include <stdlib.h>
      3 int count;
      4 void initialize(void)
      5 {
      6 count=0;
      7 }
      8 int main(void)
      9 {
     10 initialize();
     11
     12 while (FCGI_Accept() >= 0)
     13 {
     14 printf("Content-type: text/html\r\n"
     15 "\r\n"
     16 "<title>FastCGI Hello! (C, fcgi_stdio 
library)</title>"
     17 "<h1>FastCGI Hello! (C, fcgi_stdio library)</h1>"
     18 "Request number %d running on host <i>%s</i>\n",
     19 ++count, getenv("SERVER_HOSTNAME"));
     20 }
     21 return 1;
     22 }
```

which compiles fine but I am unable to configure nginx to execute it.

I read [http://wiki.nginx.org/NginxConfiguration](http://wiki.nginx.org/NginxConfiguration) but to no avail.

Also, once I will have figured this out, I will need that program to  
work with the nginx\_http\_push\_module-0.692

Nginx is otherwise working fine on my Centos 5 machine.

Could anyone point me to an example for such a configuration.

Thank you

Posted at Nginx Forum:

> **[configuratioin fastcgi C/C++ program](https://forum.nginx.org/read.php?2,93268,93268#msg-93268)**
>
> hello I have a fastcgi program like this \[code\] 1 #include "/usr/local/include/fcgi\_stdio.h" 2 #include \<stdlib.h\> 3 int count; 4 void initialize(void) 5 { 6 count=0; 7

---

<div class="post-metadata">

**Author:** ![JCR](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/j/258eb7/32.png) [@JCR](https://www.ruby-forum.com/u/JCR)\
**Post date:** [June 2, 2010, 1:32am UTC](https://www.ruby-forum.com/t/configuratioin-fastcgi-c-c-program/189498/2 "2010-06-02T01:32:10Z")

</div>

On Tue, Jun 1, 2010 at 12:31 PM, JCR [removed\_email\_address@domain.invalid](mailto:removed_email_address@domain.invalid) wrote:

> ```
> 7 }
> 18 "Request number %d running on host <i>%s</i>\n",
> 19 ++count, getenv("SERVER_HOSTNAME"));
> 20 }
> 21 return 1;
> 22 }
> 
> ```
> 
> [/code]
> 
> which compiles fine but I am unable to configure nginx to execute it.

you need to plug your code to a socket/port. nginx than talks to that  
with fcgi\_pass.

> **[Configuration File — Supervisor 4.3.0 documentation](https://supervisord.org/configuration.html)**

this is one of the options that can plug your code to socket/port (the  
“fcgi-program” directive)

> Posted at Nginx Forum: [http://forum.nginx.org/read.php?2,93268,93268#msg-93268](http://forum.nginx.org/read.php?2,93268,93268#msg-93268)
> 
> * * *
> 
> nginx mailing list  
> [removed\_email\_address@domain.invalid](mailto:removed_email_address@domain.invalid)  
> [mailman.nginx.org archive](http://nginx.org/mailman/listinfo/nginx)

–  
python/django hacker & sys admin  
[http://almirkaric.com](http://almirkaric.com) & [http://twitter.com/redduck666](http://twitter.com/redduck666)

---

<div class="post-metadata">

**Author:** ![JCR](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/j/258eb7/32.png) [@JCR](https://www.ruby-forum.com/u/JCR)\
**Post date:** [June 2, 2010, 3:53pm UTC](https://www.ruby-forum.com/t/configuratioin-fastcgi-c-c-program/189498/3 "2010-06-02T15:53:09Z")

</div>

Almir,

Thank your for your help. I have supervisor running with:  
at the end of supervisord.conf:

131 [fcgi-program:chat]  
132 command=/websites/nginx/chat.toff  
133 socket=tcp://localhost:9000

supervisor\> status  
chat RUNNING pid 4904, uptime 0:01:45

in my nginx.conf file I have:  
56 location ~ .toff$ {  
57 #include /usr/local/nginx/conf/fastcgi.conf;  
58 fastcgi\_pass localhost:9000;  
59 }

now when I browse my page, I am getting this in logs/error.log  
2010/06/02 09:45:31 [error] 5839#0: \*136 upstream prematurely closed  
connection while reading response header from upstream, client:  
70.48.66.49, server: \*.example.com, request: “GET /chat.toff HTTP/1.1”,  
upstream: “fastcgi://127.0.0.1:9000”, host: “[www.example.com:8080](http://www.example.com:8080)”

Any idea? Thanks again

Posted at Nginx Forum:

> **[Re: configuratioin fastcgi C/C++ program](https://forum.nginx.org/read.php?2,93268,93580#msg-93580)**
>
> hello I have a fastcgi program like this \[code\] 1 #include "/usr/local/include/fcgi\_stdio.h" 2 #include \<stdlib.h\> 3 int count; 4 void initialize(void) 5 { 6 count=0; 7

---

<div class="post-metadata">

**Author:** ![JCR](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/j/258eb7/32.png) [@JCR](https://www.ruby-forum.com/u/JCR)\
**Post date:** [June 2, 2010, 5:49pm UTC](https://www.ruby-forum.com/t/configuratioin-fastcgi-c-c-program/189498/4 "2010-06-02T17:49:05Z")

</div>

> 56 location /chat/ {  
> 57 include /usr/local/nginx/conf/fastcgi.conf;  
> 58 fastcgi\_pass localhost:9000;  
> 59 }

try something like this. the commented out fastcgi.conf may have  
something to do with the error. showing fastcgi.conf may be also a  
good idea

i would also check the supervisor stdout/stderr of your program

On Wed, Jun 2, 2010 at 6:52 AM, JCR [removed\_email\_address@domain.invalid](mailto:removed_email_address@domain.invalid) wrote:

> chat RUNNING pid 4904, uptime 0:01:45  
> Any idea? Thanks again
> 
> Posted at Nginx Forum: [http://forum.nginx.org/read.php?2,93268,93580#msg-93580](http://forum.nginx.org/read.php?2,93268,93580#msg-93580)
> 
> * * *
> 
> nginx mailing list  
> [removed\_email\_address@domain.invalid](mailto:removed_email_address@domain.invalid)  
> [mailman.nginx.org archive](http://nginx.org/mailman/listinfo/nginx)

–  
python/django hacker & sys admin  
[http://almirkaric.com](http://almirkaric.com) & [http://twitter.com/redduck666](http://twitter.com/redduck666)

---

<div class="post-metadata">

**Author:** ![JCR](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/j/258eb7/32.png) [@JCR](https://www.ruby-forum.com/u/JCR)\
**Post date:** [June 2, 2010, 6:18pm UTC](https://www.ruby-forum.com/t/configuratioin-fastcgi-c-c-program/189498/5 "2010-06-02T18:18:57Z")

</div>

The log file of supervisord tells me:

2010-06-02 11:59:46,441 INFO exited: chat\_04 (terminated by SIGSEGV; not  
expected)

Does that point to a memory issue with my fasctcgi program?

Posted at Nginx Forum:

> **[Re: configuratioin fastcgi C/C++ program](https://forum.nginx.org/read.php?2,93268,93641#msg-93641)**
>
> hello I have a fastcgi program like this \[code\] 1 #include "/usr/local/include/fcgi\_stdio.h" 2 #include \<stdlib.h\> 3 int count; 4 void initialize(void) 5 { 6 count=0; 7

---

<div class="post-metadata">

**Author:** ![JCR](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/j/258eb7/32.png) [@JCR](https://www.ruby-forum.com/u/JCR)\
**Post date:** [June 2, 2010, 9:01pm UTC](https://www.ruby-forum.com/t/configuratioin-fastcgi-c-c-program/189498/6 "2010-06-02T21:01:04Z")

</div>

Hi, it looks like the problem was that I was using  
getenv(“SERVER\_HOSTNAME”).

I am not sure why this happens but at least it is working now.

When I change my chat program, I do  
supervisorctl shutdown; supervisord;

to see the newer version. Is there a better way to that?

Thanks again for your idea of using supervisord. Maybe that should go  
into wiki because it is quite convenient.

Posted at Nginx Forum:

> **[Re: configuratioin fastcgi C/C++ program](https://forum.nginx.org/read.php?2,93268,93705#msg-93705)**
>
> hello I have a fastcgi program like this \[code\] 1 #include "/usr/local/include/fcgi\_stdio.h" 2 #include \<stdlib.h\> 3 int count; 4 void initialize(void) 5 { 6 count=0; 7

---

<div class="post-metadata">

**Author:** ![JCR](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/j/258eb7/32.png) [@JCR](https://www.ruby-forum.com/u/JCR)\
**Post date:** [June 2, 2010, 9:31pm UTC](https://www.ruby-forum.com/t/configuratioin-fastcgi-c-c-program/189498/7 "2010-06-02T21:31:30Z")

</div>

You can do

supervisorctl restart chat
