Aug 202010

Here is a simple example of a hello world program for FastCGI written in C. Before you can compile this, you will need to install the FastCGI devkit. At the time of writing the latest version is available from

extract, compile and install fcgi-current.tar.gz

$ tar xvzf fcgi-current.tar.gz
$ cd  fcgi-2.x.x/
$ ./configure
$ make
$ sudo make install

the c code

#include <fcgi_stdio.h>
int main( int argc, char *argv[] )
   while( FCGI_Accept() >= 0 ) {
      printf( "Content-Type: text/plain\n\n" );
      printf( "Hello world in C\n" );
   return 0;

save as hello.c
compile and linked against fcgi library

$ gcc -o hello hello.c -lfcgi

run the code using spawn-cgi

# spawn-fcgi -a127.0.0.1 -p9000 -n ./hello

Nginx configuration

server {
        listen   80;
        server_name _;

       location / {
                        # host and port to fastcgi server
                        root   /home/user/www;
                        index  index.html;


that’s for now 🙂

  14 Responses to “Nginx, fastcgi, ‘Hello World’ in C”

Comments (14)
  1. @Sabka Traffic
    Use the new 64bit release and the native/handler link for any of the new supported languages instead of the slow fcgi interface or wait for/help with a thread-safe PHP library/compiler if it’s PHP the one you need.

    It’s not “somehow exotic”, it’s exceptionally unique in the best meanings of those words. The author is using it to host his web since the first beta and the very reason to create G-WAN was because he couldn’t find the high performing platform needed to build his even more amazing “toy” services on (check the sadly read-only now official forum if curious enough).

    The one-man-team in just a couple of years created the most secure and feature-rich application server to date, (of all publicly availabe at least) even in it’s current release candidate state… and it keeps getting better at tremendous pace (check the recent 3.1.3 release) – compare that with the huge amounts of developers over decades wasted (it’s hard to find another word if you look at the end results) on polishing bad desings instead of thinking out of the box.

  2. I am trying to do the same thing but when I run ‘cgi-fcgi -connect ./echo’ it just outputs the the string and nginx reports : ‘The page you are looking for is temporarily unavailable. Please try again later.’ Any idea, link or resource?

  3. well, i don’t know what cgi application you’ve used for spawning the echo
    in my tutorial i used spawn-cgi

    spawn-fcgi -a120.0.0.1 -p9000 -n ./hello
  4. I’m just trying the same and works for me.
    The only difference is using the -start argument

    cgi-fcgi -start -connect localhost:9000 ./hello

    I’m using archlinux and following the instructions in the following page:

  5. For me , i definitely believe it always is an excellent product,and i wonder how it grows if it is not opened or maintained by a company?

 Leave a Reply

You may use these HTML tags and attributes: <a href="" title=""> <abbr title=""> <acronym title=""> <b> <blockquote cite=""> <cite> <code> <del datetime=""> <em> <i> <q cite=""> <s> <strike> <strong>




This site uses Akismet to reduce spam. Learn how your comment data is processed.