在 Amazon EC2 上安装测试应用程序

2021-12-21 00:00:00 amazon-ec2 html c++

我想使用 AWS 产品在其上构建一些应用程序.现在,我想测试一下 -

I want to use AWS products to build some application on it. For now, i want to test this -

1) 创建一个托管在 AWS 上的网页,其中包含一个简单的文本框和一个提交按钮,用于检查数字是否为质数.2) 在 EC2 上编译一个 C++ 程序来接受一个数字,如果它是质数就回复.

1) Create a webpage hosted at AWS with a simple text box and a submit button, for checking if a number is prime. 2) Compile a C++ program on EC2 to accept a number and reply if it is prime.

有人可以列出执行此操作所涉及的步骤吗?(上面的例子简单地反映了我想到的实际应用程序,有一个 http 前端和一个 C++ 后端)

Can someone list the steps involved in doing this? (The above example mirrors simplistically the actual application that i have in mind, with a http frontend and a c++ backend)

推荐答案

如果您使用默认的 Linux AMI,您将准备好标准的 Apache 安装.听起来你的应用程序的调用风格是请求-响应,所以至少在开始时,你可以使用 CGI 来让 Apache 运行你的应用程序.

If you use the default Linux AMI, you will gave a standard Apache installation ready to go. It sounds like the invocation style of your app is request-response, so at least to begin with, you could just use CGI to get Apache to run your app.

要实现这一点,您可以执行以下操作:

To achieve this, you would do something like this:

  1. 创建一个带有表单和提交按钮的静态 html 页面,通过 CGI 将表单数据传递给您的应用
  2. 将您的应用安装到适当的目录中(有关详细信息,请参阅 Apache 配置)以通过 CGI 运行它,注意确保设置了正确的权限
  3. 让您的应用解析 CGI 环境变量以收集输入
  4. 执行所需的处理
  5. 将结果输出生成为 HTTP 响应(要开始使用,只需使用 text/plain).

请注意,这里有许多安全问题需要牢记,因此对网络用户提供的所有数据进行严格验证以防止转义问题、缓冲区溢出等非常重要.

Please note that there are many security issues to keep in mind here, so it is very important to perform strict validation on all data supplied by the web user for escaping issues, buffer overflows and so on.

如果您不熟悉上述内容,您至少需要阅读 HTML 表单、Apache 配置和基本 HTTP 标头.有很多示例,以及一些涵盖该主题的好书.

If you aren't familiar with the above, you will need to read up on HTML forms, Apache configuration and basic HTTP headers at at minimum. There are plenty of examples out there, and some great books covering the topic.

为此,已经开发了各种库来促进这一点:

To this end, various libraries have been developed to facilitate this:

  • 哪个 C++ 库用于 CGI 编程?

还有许多其他选项可用于将您的应用与 Apache 连接,例如 FastCGI.

There are also many other options for interfacing your app with Apache, such as FastCGI.

相关文章