Best method to create a c++ app to communicate with nginx

Vivek Goel picture Vivek Goel · Jan 31, 2012 · Viewed 21.8k times · Source

I need to write a C++ interface that can read our data structure and provide the o/p based on query using http protocol.

Server Need
It should be able to serve 100 clients at the same time.

Why C++
All code is already written in C++. So we need to just write a http layer in C++. That's why I am choosing C++ instead of a more conventional web-programming language.

I am thinking to use nginx to serve static files and use its proxy pass to communicate with C++.

There are two approaches I have found:

  • Write a FastCGI c++ module.

  • Write a node.js c++ module.

  • Please just any other suggestion if you have

Can you please list the pros and cons for each method based on prior experience?

Answer

Christopher Smith picture Christopher Smith · Apr 21, 2014

No one here seems to have addressed the actual question, though some nice work arounds have been offered. I've been able to build C++ modules for nginx with a couple of minor changes.

  1. Change the module source file name to end with .cpp so gcc realizes it is dealing with C++.
  2. Make sure all your nginx includes (e.g. ngx_config.h, ngx_core.h, etc.) are wrapped with an extern "C" { } structure. Similarly make sure any functions called through nginx function pointers are declared with a wrapper.
  3. Add --with-ld-opt="-lstdc++" to your "configure" invocation when setting up nginx.

With those three steps your module should compile, build, link, and actually work.