Ubuntu:Ubuntu9.10
目的:移植web server到Ubuntu
window下载thttpd,地址:http://www.acme.com/software/thttpd/
1.上传thttpd到ubuntu,解压,配置,安装
$ tar zxf thttpd-2.27.tar.gz
$ cd thttpd-2.27/
$ ./configure
$ make
$ sudo make install
虽然安装有错,但不影响 将安装thttpd等程序到/usr/local/sbin,同时默认web目录是/usr/local/www 3.创建配置文件thttpd.conf,建议放到/etc目录 $cd /etc
$touch thttpd.conf
$vi thttpd.conf, 内容为:
dir=/usr/local/www #指明WebServer存放网页的根目录路径
user=root #以root用户登录,权利更大
logfile=/var/log/thttpd.log #日志文件
pidfile=/var/run/thttpd.pid #进程临时文件
port=8080 #端口号
cgipat=/cgi-bin/* #声明CGI程序的目录,注意是以dir为根目录的路径
4. 拷贝当前目录下的 index.html文件到web目录 $ sudo cp index.html /usr/local/www
5. 运行web服务器
$sudo thttpd -C /etc/thttpd.conf
6.windows浏览器上输入:http://192.168.1.199:8080(Ubuntu IP为192.168.1.199)
如果看到以下界面,就代表web服务器已经搭建好了
7.当然也可以编写test.c测试CGI程序
vi test.c,内容为:
//file: test.c
#include
#include
int main()
{
printf("Content type: text/html\n\n");
printf("\n");
printf("CGI\n");
printf("");
printf("
");
printf("This is just a cgi testpage");
printf("\n");
printf("\n");
fflush(stdout);
return 0;
}
8. 编译test.c生成cgi程序
$ gcc test.c -o test.cgi
9.将 test.cgi拷贝到cgi目录下
$ sudo cp test.cgi /usr/local/www/cgi-bin/
10. 在浏览器上输入192.168.1.199:8080/cgi-bin/test.cgi访问这个cgi程序 看到以下界面就代表cgi程序执行正常