试图让fastcgi在nginx和c++中工作

Trying to get fastcgi to work in nginx and c++

本文关键字:c++ 工作 nginx fastcgi      更新时间:2023-10-16

下面是我的c++代码和配置文件。

当我运行spawn-fcgi -a120.0.0.1 -p9000 -n ./rtb.o

我收到这个错误

spawn-fcgi: exec failed: Exec format error

这是我作为rtb.o 编写的c++代码

#include "fcgi_stdio.h"
#include <stdlib.h>
using namespace std;
int main()
  {
      int count = 1;
      while(FCGI_Accept() >= 0)
          printf("Content-type: text/htmlrn"
                 "rn"
                 "<title>FastCGI Hello!</title>"
                 "<h1>FastCGI Hello!</h1>"
                 "Request number %d running on host n",
                  ++count);
      return 0;
  }

那么,我做错了什么?

您正试图运行一个名为rtb.o的程序?这是目标文件还是可执行文件?您可能想向我们展示如何编译程序。如果你正在做类似的事情

g++ -c rtb.cpp

然后你会得到一个对象文件,你需要链接它来获得一个工作程序。尝试使用./rtb.o从您的终端运行它。如果它打印相同的消息,那么你有一个对象文件,需要尝试这样的方法:

g++ -o rtb rtb.cpp

链接时请记住添加对FCGI库的引用(使用-l选项)。