使用nginx设置fastcgi

时间:2012-02-13 11:12:50

标签: nginx fastcgi

我正在使用以下c代码

#include <fcgi_stdio.h>

/*
 * 
 */
int main(int argc, char** argv) {
    while (FCGI_Accept() >= 0) {
        printf("Content-Type: text/plain\r\n");
        printf("Hello world in C\n");
    }

    return 0;
}

我正在使用以下命令

 spawn-fcgi -a127.0.0.1 -p9000 -n ./a.out

在spawn-fcgi中,我使用fedora 15 repo安装。

Nginx配置是:

   location / {
        root html;
        fastcgi_pass 127.0.0.1:9000;
        }

我收到以下错误:

2012/02/13 16:15:45 [error] 17998#0: *1 upstream closed prematurely FastCGI stdout while reading response header from upstream, client: 127.0.0.1, server: localhost, request: "GET /hello HTTP/1.1", upstream: "fastcgi://127.0.0.1:9000", host: "127.0.0.1:8081"

有什么不对?

1 个答案:

答案 0 :(得分:0)

问题代码应该是

int main(int argc, char** argv) {
    while (FCGI_Accept() >= 0) {
        printf("Content-Type: text/plain\r\n\r\n");
        printf("Hello world in C\n");
    }

    return 0;
}
相关问题