如何在Windows下配置CGI
1. 安装好Appach
2. 在httpd.conf 中最后面添加下面的配置:
<VirtualHost *:80>
ServerAdmin andylin02@126.com #管理员的邮件
ServerName andylin.com.cn #这里是使用虚拟服务器的方式添加一个域名
ScriptAlias /cgi-bin/ "d:/local/cgi-bin/" #放置cgi的路径
DocumentRoot d:/local/htdoc #放置html文件的路径
<Directory />
Options Includes FollowSymLinks
AllowOverride None
Order allow,deny
Allow from all
</Directory>
ErrorLog logs/andylin_error_log #web错误日志文件
TransferLog logs/andylin_access_log #访问权限错误日志
</VirtualHost>
3. 在C:/WINDOWS/system32/drivers/etc/hosts中添加:
127.0.0.1 andylin.com.cn #和上面配置虚拟服务器的域名一致
4. 测试是否配置成功
1) 在"d:/local/htdoc"中添加一个htnl文件hello.html
<HTML>
<HEAD>
<TITLE>Test cgi Hello
</TITLE>
</HEAD>
<body>
<p>
<H1>Click Button To Test Cgi </H1>
</P>
<hr>
<form method="POST" action="cgi-bin/hello.cgi">
<center>
<input type=submit value="提交"> <input type=reset value="取消">
</center>
</form>
</hr>
</body>
</HTML>
2) 在vc中添加一个Win32 Console 程序, 源代码如下:
#include "stdafx.h"
#include "stdio.h"
int _tmain(int argc, _TCHAR* argv[])
{
printf("Content-Type: text/html/r/n/r/n");
printf("<html><body><h1>Hello andylin!</h1></body></html>/n");
return 0;
}
3) 编译上面的工程生成hello.exe 修改后缀为cgi
4) 将hello.cgi拷贝到"d:/local/cgi-bin"目录下
5) 打开IE浏览器,在地址栏中输入"http://andylin.com.cn/hello.html"将显示hello.html页面。
6) 点击"提交"按钮,转向"http://andylin.com.cn/cgi-bin/hello.cgi"显示"Hello andylin!"
7) 配置成功!