【发布时间】:2015-07-02 17:30:20
【问题描述】:
我无法使用 nginx 让 FCGI 应用程序在 C 中运行。我正在使用 spawn-fcgi 创建套接字并运行我的应用程序(我将其命名为 paste)
我认为这一定是我的应用程序有问题,但我相当肯定我从位于 here 的示例源中复制了所有相关部分。
这是 nginx 给我的错误:
[error] 53300#0: *4 upstream prematurely closed connection while
reading response header from upstream, client: 127.0.0.1, server:
localhost, request: "GET /test HTTP/1.1", upstream:
"fastcgi://unix:/tmp/cfcgi.sock:", host: "localhost"
这是应用程序的来源:
#include <fcgi_stdio.h>
#include <stdlib.h>
#include <stdio.h>
int main(int argc, char **argv) {
while(FCGI_Accept() >= 0) {
printf("Content-type: text/html\r\n\r\n");
printf("Hostname: %s", getenv("SERVER_HOSTNAME"));
}
return EXIT_SUCCESS;
}
nginx中的相关配置变化:
location /test {
include fastcgi_params;
fastcgi_pass unix:/tmp/cfcgi.sock;
}
还有 spawn-fcgi 命令:
spawn-fcgi -s /tmp/cfcgi.sock -M 0777 -P cfcgi.pid -- paste
【问题讨论】: