修改apache配置

<Directory "${INSTALL_DIR}/cgi-bin">
    AllowOverride None
    Options None
    Require all granted
</Directory>

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

<Directory "${INSTALL_DIR}/cgi-bin">
    AllowOverride None
    Options ExecCGI
    Require all granted
</Directory>
AddHandler cgi-script .exe .cgi .pl

编写hello world程序

#include<stdio.h>
#include<stdlib.h>

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

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

访问网站

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


背景知识:

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


参考网站:



登陆发表评论