Forwarding apache request to a c++ program Forwarding apache request to a c++ program apache apache

Forwarding apache request to a c++ program


There are a few options.

CGI is simple and has been around forever. Under CGI, the web server would spawn a separate process for every web request. As you mentioned in your comment, you could write a CGI script that makes RPC calls to your C++ program.

FastCGI is an alternative to CGI; instead of spawning a separate process for every web request, it defines a protocol for letting the web server dispatch multiple web requests to a single long-running process. It works quite well for web applications. However, for your scenario, where you have a preexisting server process that needs to add a web interface, it may not work as well; based on my limited understanding, web servers typically expect to start and stop the long-running FastCGI processes themselves (in response to incoming requests, server load, idle time, etc.) instead of connecting to preexisting FastCGI processes. (Most servers would let you reconfigure this, I think, but it's not the default.)

You can also always embed a web server like Mongoose or cpp-netlib in your C++ process and set up Apache to proxy requests to it. This might be your best approach. (Mongoose, for example, is extremely easy to embed.)

Finally, you can use a full-fledged Apache module (either redesign your C++ server as an Apache module or have an Apache module to communicate with your C++ service). This is probably more complicated than you want to do, although there are existing projects like CPPSERV that take this approach.