修改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,編譯為可執(zhí)行文件helloworld.exe,然后復(fù)制到apache的cgi-bin目錄即可
訪問網(wǎng)站
在瀏覽器輸入localhost/cgi-bin/helloworld.exe
即可看到hello world, 你好
背景知識:
通用網(wǎng)關(guān)接口(Common Gateway Interface/CGI)是一種重要的互聯(lián)網(wǎng)技術(shù),可以讓一個客戶端,從網(wǎng)頁瀏覽器向執(zhí)行在網(wǎng)絡(luò)服務(wù)器上的程序請求數(shù)據(jù)。CGI描述了服務(wù)器和請求處理程序之間傳輸數(shù)據(jù)的一種標準。
參考網(wǎng)站: