Configuratioin fastcgi C/C++ program

hello

I have a fastcgi program like this

      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 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:
http://forum.nginx.org/read.php?2,93268,93268#msg-93268

On Tue, Jun 1, 2010 at 12:31 PM, JCR [email protected] 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.

http://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


nginx mailing list
[email protected]
http://nginx.org/mailman/listinfo/nginx


python/django hacker & sys admin
http://almirkaric.com & http://twitter.com/redduck666

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

Any idea? Thanks again

Posted at Nginx Forum:
http://forum.nginx.org/read.php?2,93268,93580#msg-93580

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 [email protected] 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


nginx mailing list
[email protected]
http://nginx.org/mailman/listinfo/nginx


python/django hacker & sys admin
http://almirkaric.com & http://twitter.com/redduck666

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:
http://forum.nginx.org/read.php?2,93268,93641#msg-93641

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:
http://forum.nginx.org/read.php?2,93268,93705#msg-93705

You can do

supervisorctl restart chat