Forum: NGINX C fast-cgi implementation

Announcement (2017-05-07): is now read-only since I unfortunately do not have the time to support and maintain the forum any more. Please see and for other Rails- und Ruby-related community platforms.
Huy Phan (Guest)
on 2009-04-24 05:59
(Received via mailing list)
I'm doing some benchmarks on Nginx against Apache with PHP and C/C++.
as far as I know, Nginx is lack of supporting CGI, can you suggest me a
way to
implement Nginx fast-cgi with C/C++ ?
I googled these days but didn't find any solution.
Roger H. (Guest)
on 2009-04-24 07:11
(Received via mailing list)
There's an fcgi C library here, first link on the page.
Charles McGarvey (Guest)
on 2009-04-24 07:19
(Received via mailing list)

Download the "Development Kit" which includes a C library implementation
of FastCGI and C/C++ examples.  The library is very easy to learn, so
you should be up and running quickly.  Read the fcgiapp.h file to get

Huy Phan (Guest)
on 2009-04-25 09:07
(Received via mailing list)
Charles McGarvey <onefriedrice@...> writes:

Thanks for this page,
I see that Nginx has the module NginxHttpFcgiModule which allows Nginx
interact with FastCGI processes, but we have to start the fastcgi server
I wrote the code with FastCGI Dev Kit but don't know how to start the
server with it.
The document from only mentions about servers that support
and execute itself.
Charles McGarvey (Guest)
on 2009-04-25 09:40
(Received via mailing list)
Huy Phan wrote:
>> Chaz
Here's some sample code to help you get started (may not compile but you
get the idea):

#include <fcgiapp.h>

int main()
    int sockfd = FCGX_OpenSocket("/var/run/myfcgiserver.sock", 1024);
    FCGX_Request request;

    FCGX_InitRequest(&request, sockfd, 0);

    while (FCGX_Accept_r(&request) == 0)
        FCGX_FPrintF(request.out, "Content-type: text/html\r\n"
            "<h1>Hello World!</h1>");

You're right, nginx won't start your fastcgi server for you, so just run
it yourself.  Personally, I find it easy enough to just create an init
script for any fcgi app I want running.

Then configure nginx something like this:

        location ~ fcgi-bin/.*$ {
            include /etc/nginx/fastcgi_params;
            fastcgi_pass    unix:/var/run/myfcgiserver.sock;
            fastcgi_index    whatever;

With this, any request to yourserver/fcgi-bin/... will be sent to your
fastcgi server.

One final note: If you want to use TCP rather than a unix socket, change
the first argument of FCGX_OpenSocket to ":portnum" (i.e. ":2000" -- you
need the colon).  Then use "fastcgi_pass  yourfcgiserver:2000;" in the
nginx config.

Hope that helps..
Huy Phan (Guest)
on 2009-04-25 10:33
(Received via mailing list)
Thank you, it's working like a charm.
This topic is locked and can not be replied to.