在从上游读取响应标头时,c++和fastcgi-upstream提前关闭了fastcgi stdout
c++ and fastcgi - upstream closed prematurely FastCGI stdout while reading response header from upstream
我正在使用nginx、factcgi和spawn fcgi,并试图让它发挥作用。
我开始生成fcgi如下:
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
当我去时
http://127.0.0.1:83/forecast.fcgi
我得到一个502错误的
当我在命令行中查看派生fcgi的输出时,我会看到正确的输出。。。请参阅文章的最底部:
在nginx日志中,我得到了这个:
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++代码:
int main() {
FCGX_Init();
while(FCGI_Accept() >= 0){
printf("Content-type: text/htmlrn"
"rn"
"<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部分:
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时控制台的输出。
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>
是否需要#include"fcgi_stdio.h"?
如果我从头开始写应用程序,我会显式地使用FCGI_printf,而不是依赖于FCGI_stdio.h中的#define magic。
相关文章:
- FastCGI Server C++
- 与Spawn-fcgi相比,具有C 的FastCGI
- 用于单元测试的FastCGI和boost::asio
- 如何使用FastCGI C/C 应用程序访问POST请求的主体
- 简单的多线程fastcgi应用程序总是崩溃
- 用nginx在c++中用fastcgi访问环境变量
- PHP7 和 IIS8 HTTP 错误 500.0 - FastCGI 进程意外退出
- 如何在 Amazon EC2(运行 Ubuntu Lucid)上设置 Nginx,并针对 FastCGI/FastCGI
- 在运行 ubuntu 的服务器中构建 FastCGI 时出错
- 同一服务器上的多个并发 FastCGI 应用程序
- FastCGI发送图像数据作为响应C++
- Nginx + fastcgi multithreading
- 为什么 getenv( "QUERY_STRING" ) 在 FastCGI C++ 程序中返回 null?
- Apache FastCGI应用程序无法找到合适的libfcgi(Mac OS 10.8.4)
- 从服务器接收到Wt FastCGI不完整的标头(0字节)
- FastCGI:检索请求头
- FastCGI c++存储请求
- 试图让fastcgi在nginx和c++中工作
- 如何向fastcgi应用程序呼叫/发送消息
- 在fastCGI中重定向url时合并消息体