Best method to create a c++ app to communicate with nginx
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.
- Change the module source file name to end with
.cpp
so gcc realizes it is dealing with C++. - Make sure all your Nginx includes (e.g.
ngx_config.h
,ngx_core.h
, etc.) are wrapped with anextern "C" { }
structure. Similarly make sure any functions called through Nginx function pointers are declared with a wrapper. - 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.
What you are asking is basically how to turn the c++ process that holds your data strutures into a webserver. That might not be the best way to go about it. (Then again, maybe it is in your situation. It depends on the complexity of the c++ process's interfaces you are trying to expose i guess.)
Anyways, I would try to stick a small http frontend in between the c++ process and the clients that could do the http work and communicate with the c++ backend process using some simple messaging protocol like ZeroMQ/zmq.
zmq in c/c++ is fairly straight forward, and its very efficient and very fast. Using zmq you could very quickly setup a simple webserver frontend in python, or whatever language you prefer that has zmq bindings, and have that frontend communicate asyncronously or syncronously with the backend c++ process using zmq.
The c++ examples and the guide are nice starting points if you are looking into using zmq.
For Node.js there are also a few examples.