Wednesday, April 17, 2013

How to use C as a scripting language in Nginx

Use either:

1. Instead of building a web server, you can consider to write a fastcgi
or scgi application.

http://www.fastcgi.com/devkit/doc/fastcgi-prog-guide/ap_guide.htm

2. You could look at the lua module. I hardly ever write C for nginx now.

http://openresty.org/ has some examples.

Also, I'm a big fan of using HTTP over things like fastcgi,scgi, etc.
Much easier to test, debug, etc. But that's just my opinion.

3. fcgiwrap http://wiki.nginx.org/Fcgiwrap

4. thttpd http://wiki.nginx.org/ThttpdCGI

5. mini-httpd

Nginx doesn't support CGI.

The best solution probably depends on what you're trying to achieve and your particular circumstances. As well as the solutions already suggested, one method I've used is to build the C program against libevent, effectively using libevent to build a mini webserver that is running all the time. nginx can then use that as an upstream proxy.

Start here:
http://libevent.org/

libevent has all of the hard stuff done for you. You basically just need to use it's API to get hold of all the HTTP request information and to let it handle the response to the user.

Reference:
http://www.ruby-forum.com/topic/3135016

No comments: