Welcome! Log In Create A New Profile


Re: C fast-cgi implementation

Charles McGarvey
April 25, 2009 01:32AM
Huy Phan wrote:
> Charles McGarvey <onefriedrice@...> writes:
>> http://www.fastcgi.com/drupal/node/5
>> 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 going.
>> Cheers,
>> Chaz
> Thanks for this page,
> I see that Nginx has the module NginxHttpFcgiModule which allows Nginx to
> interact with FastCGI processes, but we have to start the fastcgi server myself.
> I wrote the code with FastCGI Dev Kit but don't know how to start the FastCGI
> server with it.
> The document from fastcgi.com only mentions about servers that support FastCGI
> and execute itself.
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..

C fast-cgi implementation

Huy PhanApril 23, 2009 09:46PM

Re: C fast-cgi implementation

Roger HooverApril 23, 2009 10:59PM

Re: C fast-cgi implementation

Charles McGarveyApril 23, 2009 11:10PM

Re: C fast-cgi implementation

Huy PhanApril 25, 2009 12:51AM

Re: C fast-cgi implementation

Charles McGarveyApril 25, 2009 01:32AM

Re: C fast-cgi implementation

Huy PhanApril 25, 2009 02:21AM

Sorry, only registered users may post in this forum.

Click here to login

Online Users

Guests: 97
Record Number of Users: 5 on August 04, 2015
Record Number of Guests: 244 on October 02, 2015
Powered by nginx    Powered by FreeBSD    PHP Powered    Powered by Percona     ipv6 ready