apache cgi 程序: End of script output before headers

测试linux Apache cgi程序:

#include <stdio.h>
int main(){
        printf("abc");
        return 0;
}

目录:/var/www/cgi-bin/test.cpp

编译:

gcc test.cpp -o test.cgi

访问,出现500错误:

http://ip/cgi-bin/test.cgi

日志:

[Thu Jul 06 10:28:58.784372 2017] [cgi:error] [pid 9739] [client 192.168.2.24:33535] End of script output before headers: test.cgi

解决:

修改程序为:

#include <stdio.h>
int main(){
        printf("Content-Type: text/html\n\n");
        printf("abc");
        return 0;
}