C语言编写cgi程序hello world

修改apache配置


    AllowOverride None
    Options None
    Require all granted


//修改为下面的配置,然后重启


    AllowOverride None
    Options ExecCGI
    Require all granted

AddHandler cgi-script .exe .cgi .pl

编写hello world程序

#include
#include

void main()
{
    printf("Content-Type:text/html;\r\n\r\n");
    printf("hello world, 你好");
}

将上述文件保存为main.c,编译为可执行文件helloworld.exe,然后复制到apache的cgi-bin目录即可

访问网站

在浏览器输入localhost/cgi-bin/helloworld.exe即可看到hello world, 你好


背景知识:

通用网关接口(Common Gateway Interface/CGI)是一种重要的互联网技术,可以让一个客户端,从网页浏览器向执行在网络服务器上的程序请求数据。CGI描述了服务器和请求处理程序之间传输数据的一种标准。


参考网站:

  • c语言写cgi运行在apache上
  • C语言编写cgi程序hello world

你可能感兴趣的:(C语言编写cgi程序hello world)