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

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?

Problem courtesy of: Vivek Goel


I think I will go forward with Nginx module devlopment

Why ?

  1. It don’t require any other library dependency like fastcgi and other.
  2. I can use all feature of nginx inside my module.

Solution courtesy of: Vivek Goel


try G-WAN

you can use your c++ application directly, and G-WAN is fast as hell, faster than nginx.

Discussion courtesy of: Peter

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

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

Discussion courtesy of: Kim Bowles Sørhus

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.

Discussion courtesy of: Christopher Smith

This recipe can be found in it’s original form on Stack Over Flow

Node.js Recipes责编内容来自:Node.js Recipes (源链) | 更多关于

本站遵循[CC BY-NC-SA 4.0]。如您有版权、意见投诉等问题,请通过eMail联系我们处理。
酷辣虫 » 综合编程 » Best method to create a c++ app to communicate with nginx

喜欢 (0)or分享给?

专业 x 专注 x 聚合 x 分享 CC BY-NC-SA 4.0

使用声明 | 英豪名录