首页
学习
活动
专区
圈层
工具
发布
社区首页 >问答首页 >c++和fastcgi -在从上游读取响应头时过早关闭FastCGI标准输出

c++和fastcgi -在从上游读取响应头时过早关闭FastCGI标准输出
EN

Stack Overflow用户
提问于 2013-02-21 19:47:51
回答 1查看 2.2K关注 0票数 1

我正在使用nginx、factcgi和spawn-fcgi,并试图让它正常工作。

我按如下方式启动spawn-fcgi:

代码语言:javascript
复制
g++ rtbTimeSeries.cpp -o forecast.fcgi -I/home/ubuntu/cpp/boost_1_52_0/ -I/home/ubuntu/cpp/NR_C301/ -lfcgi++ -lfcgi
spawn-fcgi -a 127.0.0.1 -p 8010 -n forecast.fcgi

当我转到

代码语言:javascript
复制
http://127.0.0.1:83/forecast.fcgi 

我得到一个502错误

当我在命令行中查看spawn-fcgi的输出时,我在post的最底部看到了正确的output...see:

在nginx日志中,我得到了这个:

代码语言:javascript
复制
2013/02/21 19:42:39 [error] 16342#0: *39 upstream closed prematurely FastCGI stdout while reading response header from upstream, client: 127.0.0.1, server: 127.0.0.1, request: "GET /forecast.fcgi HTTP/1.1", upstream: "fastcgi://127.0.0.1:8010", host: "127.0.0.1:83"

下面是我的c++代码:

代码语言:javascript
复制
int main() {
    FCGX_Init();
    while(FCGI_Accept() >= 0){
        printf("Content-type: text/html\r\n"
                       "\r\n"

                       "<title>FastCGI Hello!</title>"
                       "<h1>FastCGI Hello!</h1>"
                       "Request number %d running on host <i>%s</i>\n",
                        ++count, getenv("SERVER_NAME"));
    }
    return 0;
}

这是我的nginx.conf部分:

代码语言:javascript
复制
server {
              listen 83;
              server_name 127.0.0.1;

             location / {
          fastcgi_pass   127.0.0.1:8010;

          fastcgi_param  GATEWAY_INTERFACE  CGI/1.1;
          fastcgi_param  SERVER_SOFTWARE    nginx;
          fastcgi_param  QUERY_STRING       $query_string;
          fastcgi_param  REQUEST_METHOD     $request_method;
          fastcgi_param  CONTENT_TYPE       $content_type;
          fastcgi_param  CONTENT_LENGTH     $content_length;
          fastcgi_param  SCRIPT_FILENAME    $document_root$fastcgi_script_name;
          fastcgi_param  SCRIPT_NAME        $fastcgi_script_name;
          fastcgi_param  REQUEST_URI        $request_uri;
          fastcgi_param  DOCUMENT_URI       $document_uri;
          fastcgi_param  DOCUMENT_ROOT      $document_root;
          fastcgi_param  SERVER_PROTOCOL    $server_protocol;
          fastcgi_param  REMOTE_ADDR        $remote_addr;
          fastcgi_param  REMOTE_PORT        $remote_port;
          fastcgi_param  SERVER_ADDR        $server_addr;
          fastcgi_param  SERVER_PORT        $server_port;
          fastcgi_param  SERVER_NAME        $server_name;
        }


    }

下面是当我点击浏览器中的url时控制台的输出。

代码语言:javascript
复制
spawn-fcgi -a 127.0.0.1 -p 8010 -n forecast.fcgi
Content-Type: text/plain

Hello world in C
Content-type: text/html

<title>FastCGI Hello!</title><h1>FastCGI Hello!</h1>Request number 1 running on host <i>127.0.0.1</i>
Content-Type: text/plain

Hello world in C
Content-type: text/html

<title>FastCGI Hello!</title><h1>FastCGI Hello!</h1>Request number 2 running on host <i>127.0.0.1</i>
Content-Type: text/plain

Hello world in C
Content-type: text/html

<title>FastCGI Hello!</title><h1>FastCGI Hello!</h1>Request number 3 running on host <i>127.0.0.1</i>
Content-Type: text/plain

Hello world in C
Content-type: text/html

<title>FastCGI Hello!</title><h1>FastCGI Hello!</h1>Request number 4 running on host <i>127.0.0.1</i>
Content-Type: text/plain

Hello world in C
Content-type: text/html

<title>FastCGI Hello!</title><h1>FastCGI Hello!</h1>Request number 5 running on host <i>127.0.0.1</i>
EN

回答 1

Stack Overflow用户

发布于 2013-03-05 00:22:14

你需要#包含"fcgi_stdio.h“吗?

如果我从头开始编写一个应用程序,我会显式地使用FCGI_printf,而不是依赖于fcgi_stdio.h中的#define魔术。

票数 0
EN
页面原文内容由Stack Overflow提供。腾讯云小微IT领域专用引擎提供翻译支持
原文链接:

https://stackoverflow.com/questions/15001480

复制
相关文章

相似问题

领券
问题归档专栏文章快讯文章归档关键词归档开发者手册归档开发者手册 Section 归档