将apache请求转发到c ++程序 [英] Forwarding apache request to a c++ program

查看:221
本文介绍了将apache请求转发到c ++程序的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我基本上在寻找如何处理这个问题的提示和技巧。

I am basically looking for tips and tricks on how to approach that problem.

我有一个用C ++编写的服务器软件(Linux)。我需要做的是
提供一些信息,这是在软件内部生成,通过
一个http调用apache webserver。

I have a Server Software (Linux), which is written in C++. What I need to do is to provide some information, that is generated inside that software, via a http call to the apache webserver.

当然可以将数据存储在数据库中并为其编写servlet,或者使用IPC获取数据,但我想保持简单并捆绑在一个文件中。

Of course it would be possible to store the data in the database and write a servlet for it, or use IPC to get the data, but I want to keep it simple and bundled in one file. And also I want to know if the idea would work.

所以工作流程如下:
Client - > Apache Webserver - > C ++ Software

So the workflow would look like: Client -> Apache Webserver -> C++ Software

有没有任何现有的库或者可以处理Apache - > C ++连接的东西?或者它会是一样的东西,只是重定向请求到一个套接字在c + +和手动?

Is there any existing library or something that could handle the Apache -> C++ connection? Or would it be something like just redirecting the request to a socket in c++ and do it manually? Basically something like the tomcat connector.

请注意,服务器软件在后台永久运行,并且不应该通过调用开始

Please note that the server software is running permanently in the background, and should not be "started" by the call

推荐答案

有几个选项。

CGI 很简单,已经一直存在。在CGI下,Web服务器将为每个Web请求生成一个单独的进程。正如您在注释中提到的,您可以编写一个CGI脚本,以便对您的C ++程序进行RPC调用。

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 是CGI的替代品;而不是为每个Web请求生成一个单独的进程,它定义了一个协议,让Web服务器将多个Web请求分派到一个长时间运行的进程。它适用于Web应用程序。但是,对于您的场景,您有一个预先存在的服务器进程,需要添加一个Web界面,它可能不会工作,基于我的有限理解,Web服务器通常期望启动和停止长时间运行的FastCGI进程本身(响应传入请求,服务器负载,空闲时间等),而不是连接到预先存在的FastCGI进程。 (大多数服务器会让你重新配置这个,我想,但它不是默认的。)

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.)

你也可以总是嵌入一个web服务器,如 Mongoose cpp-netlib ,并设置Apache代理对它的请求。这可能是你最好的方法。 (例如,Mongoose很容易嵌入)

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.)

最后,您可以使用一个成熟的Apache模块(重新设计C ++服务器作为Apache模块,或者有一个Apache模块与C ++服务通信)。这可能比您想要的更复杂,虽然有像 CPPSERV 这样的现有项目方法。

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.

这篇关于将apache请求转发到c ++程序的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆