2012-12-20 65 views
1

我想用C++编写一个测试cgi程序。但是,当我设置的配置文件如下:如何配置Apache服务器以使用cgi程序?

ScriptAlias /cgi-bin/ "F:/workbench/cgi-bin/" 
<Directory "F:/workbench/cgi-bin"> 
AllowOverride None 
Options ExecCGI 
Order allow,deny 
Allow from all 
</Directory> 
AddHandler cgi-script .exe .pl .cgi 

然后写一个HelloWorld程序如下:

#include <stdio.h> 
int main(void) 
{ 
    printf("\n"); 
    printf("Hello, World!\n"); 
    return 0; 
} 

,当我重新启动与G ++ HELLO.CPP -o hello.cgi 编译服务器并访问cgi:localhost \ cgi-bin \ hello.cgi 它不起作用。

+0

具有类似的问题。 WHM/cPanel环境? – 2013-01-22 22:51:18

回答

0

您需要添加一个HTTP标头来描述输出。 Http Header和Http正文由两个新行字符分隔。我认为如果你包含一个像“content-type:text/plain”这样的简单头文件,你的代码就可以工作。换句话说,尝试与:

#include <stdio.h> 
int main(void) { 
    printf("Content-type: text/plain\n"); 
    printf("\n"); 
    printf("Hello, World!\n"); 
    return 0; 
} 
相关问题