Chinaunix首页 | 论坛 | 博客
  • 博客访问: 4588236
  • 博文数量: 1148
  • 博客积分: 25453
  • 博客等级: 上将
  • 技术积分: 11949
  • 用 户 组: 普通用户
  • 注册时间: 2010-05-06 21:14
文章分类

全部博文(1148)

文章存档

2012年(15)

2011年(1078)

2010年(58)

分类: 嵌入式

2011-04-07 14:27:57

参考资料:
           tek大侠博客 thttpd 篇章
           yaopingcs的专栏 解决cgi 访问问题

1.下载 thttpd web 服务器
  我下载的是thttpd-2.25b.tar.gz


2.解压文件
  1. ywx@yuweixian:~/yu/src/web-server-src$ ls
  2. thttpd-2.25b.tar.gz
  3. ywx@yuweixian:~/yu/src/web-server-src$ tar zxfv thttpd-2.25b.tar.gz

3.编译 thttpd,编译结束,在目录下生成 thttpd 可执行文件
  编译时,出现一个错误,请看 错误解决 小节
  1. ywx@yuweixian:~/yu/src/web-server-src/thttpd-2.25b$CC=arm-linux-gcc ./configure --host=arm-linux-

  2. ywx@yuweixian:~/yu/src/web-server-src/thttpd-2.25b$ make

4.配置
  1.复制文件到自己的文件系统中
  1. ywx@yuweixian:~/yu/src/web-server-src/thttpd-2.25b$ sudo cp thttpd /opt/me_linux/root-2.6.33/usr/sbin/

  2. ywx@yuweixian:~/yu/src/web-server-src/thttpd-2.25b$ sudo cp contrib/redhat-rpm/thttpd.conf /opt/me_linux/root-2.6.33/etc/
  2.修改 thttpd.conf 为
  1. dir=/etc/thttpd/html
  2. chroot
  3. user=root# default = nobody
  4. logfile=/etc/thttpd/log/thttpd.log
  5. pidfile=/etc/thttpd/run/thttpd.pid

  3.在文件系统下建立 上述提到的文件
  1. root@yuweixian:/opt/me_linux/root-2.6.33/etc# mkdir thttpd
  2. root@yuweixian:/opt/me_linux/root-2.6.33/etc# cd thttpd/
  3. root@yuweixian:/opt/me_linux/root-2.6.33/etc/thttpd# mkdir log run html
  4. root@yuweixian:/opt/me_linux/root-2.6.33/etc/thttpd# ls
  5. log run html           #建立三个文件夹


ywx@yuweixian:~/yu/src/web-server-src/thttpd-2.25b$ sudo cp index.html  /opt/me_linux/root-2.6.33/etc/thttpd/html/                 #复制 网页
 
root@yuweixian:/opt/me_linux/root-2.6.33/etc/thttpd/run# touch thttpd.pid  建立 thttp.pid 文件
root@yuweixian:/opt/me_linux/root-2.6.33/etc/thttpd/run# cd ..
root@yuweixian:/opt/me_linux/root-2.6.33/etc/thttpd# ls
html  log  run
root@yuweixian:/opt/me_linux/root-2.6.33/etc/thttpd# cd log/
root@yuweixian:/opt/me_linux/root-2.6.33/etc/thttpd/log# touch thttpd.log  建立 thttpd.log 文件
root@yuweixian:/opt/me_linux/root-2.6.33/etc/thttpd/log#


root@yuweixian:/opt/me_linux/root-2.6.33/etc# chmod 777 *



5.编译生成  root-2.6.33.bin 文件系统
  1. root@yuweixian:/opt/me_linux# mkyaffs2image root-2.6.33 root-2.6.33.bin

6.开发板上执行命令 执行 thttpd
  1. [root@yuweixian /]# thttpd -c /etc/thttpd.conf
7.错误解决
 1.出错信息:
  1. htpasswd.c:52:12: error: conflicting types for 'getline'
  2. /home/ywx/arm-cross/arm-2010.09/bin/../arm-none-linux-gnueabi/libc/usr/include/stdio.h:651:20: note: previous declaration of 'getline' was here
  3. make[1]: *** [htpasswd.o] 错误 1
  4. make[1]:正在离开目录 `/home/ywx/yu/src/web-server-src/thttpd-2.25b/extras
 2.解决
  1. 问题分析:
  2.    htpasswd.c 文件中的 getline 与 头文件有冲突
  3. 解决:
  4. ywx@yuweixian:~/yu/src/web-server-src/thttpd-2.25b$ sudo gedit extras/htpasswd.c

  5. 将 htpasswd.c 文件中的 getline 修改为 getline1


8.全部的执行过程
  1. VFS: Mounted root (yaffs filesystem) on device 31:2.
  2. Freeing init memory: 196K
  3. Try to bring eth0 interface up ...

  4. Please press Enter to activate this console. ifconfig eth0 hw ether 10:23:45:67:89:ab
  5. eth0: link down
  6. ifconfig eth0 192.168.1.6 netmask 255.255.255.0 up
  7. add default gw 192.168.1.2
  8. Done
  9. eth0: link up, 100Mbps, full-duplex, lpa 0x41E1

  10. [root@yuweixian /]# ls
  11. bin home lost+found proc sys var
  12. dev lib mnt root tmp web
  13. etc linuxrc opt sbin usr
  14. [root@yuweixian /]# thttpd -c /etc/thttpd.conf
  15. [root@yuweixian /]# ping 192.168.1.7
  16. PING 192.168.1.7 (192.168.1.7): 56 data bytes
  17. 64 bytes from 192.168.1.7: seq=0 ttl=64 time=6.481 ms
  18. 64 bytes from 192.168.1.7: seq=1 ttl=64 time=1.186 ms
  19. ^C
  20. --- 192.168.1.7 ping statistics ---
  21. 2 packets transmitted, 2 packets received, 0% packet loss
  22. round-trip min/avg/max = 1.186/3.833/6.481 ms

9.效果截图



10.添加cgi功能
默认配置下,thttpd不可以运行GCI(特别是动态编译的CGI程序)要想使用CGI支持功能,必须更改thttpd.conf的配置:

  1. # This section overrides defaults
  2. dir=/etc/thttpd/html
  3. #achroot
  4. user=root# default = nobody
  5. logfile=/etc/thttpd/log/thttpd.log
  6. pidfile=/etc/thttpd/run/thttpd.pid
  7. # This section _documents_ defaults in effect
  8.  port=80
  9. # port参数用于更改端口号(可不改,若还运行别的web服务器,则需要不同端口)
  10. # nosymlink# default = !chroot
  11. # novhost
  12. cgipat=/cgi-bin-thttpd

11.建立 /cgi-bin-thttpd文件,添加cgi 程序
   1.添加程序一,编译thttpd 是生成的cgi程序
  1. ywx@yuweixian:~/yu/src/web-server-src/thttpd-2.25b$ sudo cp cgi-bin/printenv /opt/me_linux/root-2.6.33/cgi-bin-thttpd/
   2.添加自己建立的helloweb程序
  1. include<stdio.h>
  2. main()
  3. {
  4.     printf("content-type:text/html\n\n");
  5.     printf("\n");
  6.     printf("CGI Output\n");
  7.     printf("\n");
  8.     printf("

    Hello,Web Server.

    \n");

  9.     printf("\n");
  10.     printf("\n");
  11.     exit(0);
  12. }
arm-linux-gcc -o helloweb.cgi helloweb.c
cp heloweb.cgi /opt/me_linux/root-2.6.33/cgi-bin-thttpd/

12,修改权限,否则不能真确访问 cgi ,不能有 x 权限
   具体可参考: yaopingcs的专栏 解决cgi 访问问题
  1. root@yuweixian:/opt/me_linux/root-2.6.33/cgi-bin-thttpd# ls
  2. helloweb.cgi printenv
  3. root@yuweixian:/opt/me_linux/root-2.6.33/cgi-bin-thttpd# chmod 666 *

13 访问结果
 
  1. [root@yuweixian /]# thttpd -c /etc/thttpd-cgi.conf




































阅读(1987) | 评论(0) | 转发(0) |
给主人留下些什么吧!~~