Porting thttpd web server to ARM-Linux

Development:
    kernel:2.6.31-14-generic ubuntu9.10
    cross-tools:arm-linux-gcc version 4.1.2
Target
    kernel: 2.6.28.9 MOZART380 armv5tejl

<1>下载thttpd
    下载地址:http://www.acme.com/software/thttpd/
    Version:2.25b
<2>解压thttpd
    tar -xvzf thttpd-2.25b.tar.gz
    cd thttpd-2.25b/
<3>configure
    export CC=arm-linux-gcc (path/to/arm-linux-gcc)
    ./configure --host=arm-linux
    make
<4>拷贝thttpd
    cp thttpd /path/to/target-filesystem/thttpd/
    cp /etc/thttpd/* /path/to/target-filesystem/thttpd/
<5>创建子dir
    cd /path/to/target-filesystem/thttpd/
    mkdir www
    mkdir log
    mkdir -m 777 -p www/cgi-bin
<6>修改运行时conf
    gedit thttpd.conf
    正确设置以下参数
    port=80
    dir=/path/to/target-filesystem/thttpd/www
    #chroot        [2]
    user=root    [3]
    cgipat=/cgi-bin/*
    throttles=./throttle.conf[4]
    logfile=/path/to/target-filesystem/thttpd/log/thttpd.log
    pidfile=/path/to/target-filesystem/thttpd/log/thttpd.pid
    host=YourHostName
<7>运行thttpd
    ./thttpd -C thttpd.conf
<8>静态页面测试
    编写测试程序
    index.html
    ///
        <html>
        <head>
        <title>Welcome to nginx!</title>
        </head>
        <body bgcolor="white" text="black">
        <center><h1>Welcome to thttpd !</h1></center>
        </body>
        </html>
    ///
        拷贝
        cp index.html /path/to/target-filesystem/thttpd/www/
    测试
    http://YOURSIP/
<9>CGI脚本测试
    编写测试程序
    number.c
    ///
       #include <stdio.h>

        int main(void)
        {
        int i = 10;
        printf("Content-type: text/html\n\n");
        printf("<html>\n");
        printf("<head><title>CGI Output</title></head>\n");
        printf("<body>\n");
        while(i)
            printf("<h1>%d\n</h1>\n",i--);
        printf("<body>\n");
        printf("</html>\n");
        return 0;
        }
    ///
    交叉编译
    arm-linux-gcc -o number.cgi number.c
    拷贝至cgi-bin
        cp number.cgi /path/to/target-filesystem/thttpd/www/cgi-bin/
    更改属性
        chmod 755 number.cgi
    测试
        http://YOURSIP/cgi-bin/number.cgi

Q/A:
1.thttpd.conf可以在何处获取
A:thttpd-2.25b并没有thttpd.conf,可以使用host端的thttpd.conf
   如果host没有安装thttpd
   sudo apt-get install thttpd
   cp /etc/thttpd/* /path/to/target-filesystem/thttpd/

2.无法打开throttle.conf: No such file or directory
A:查看thttpd.conf,确保throttle.conf的配置路径指向其存放路径
  由于bean将其放在了thttpd/目录下,所以设置如下
  throttles=./throttle.conf

3.出现“unknown user - 'www-data' ”的错误
A:查看thttpd.conf,确保user的配置在target中存在
  bean裁剪filesys没有提供adduser,所以设置如下
  user=root

4.出现“chdir: No such file or directory ”的错误
A:查看thttpd.conf, 确保dir的设置正确
  bean将所有的测试放于/exchange下,关于dir的设置如下
  dir=/exchange/thttpd/www
  此处的dir是cgipat的父目录

5.出现“cannot load the lib xxxxx”
A:查看thttpd以来的动态库
  arm-9tdmi-linux-gnu-readelf -d thttpd
  ************************************************************************

Dynamic section at offset 0x11368 contains 22 entries:
  Tag        Type                         Name/Value
 0x00000001 (NEEDED)                     Shared library: [libcrypt.so.0]
 0x00000001 (NEEDED)                     Shared library: [libc.so.0]
 0x0000000c (INIT)                       0x9468
 0x0000000d (FINI)                       0x15acc
 0x00000019 (INIT_ARRAY)                 0x2135c
 0x0000001b (INIT_ARRAYSZ)               4 (bytes)
 0x0000001a (FINI_ARRAY)                 0x21360
 0x0000001c (FINI_ARRAYSZ)               4 (bytes)
 0x00000004 (HASH)                       0x8108
 0x00000005 (STRTAB)                     0x8cd0
 0x00000006 (SYMTAB)                     0x84a0
 0x0000000a (STRSZ)                      1022 (bytes)
 0x0000000b (SYMENT)                     16 (bytes)
 0x00000015 (DEBUG)                      0x0
 0x00000003 (PLTGOT)                     0x21440
 0x00000002 (PLTRELSZ)                   872 (bytes)
 0x00000014 (PLTREL)                     REL
 0x00000017 (JMPREL)                     0x9100
 0x00000011 (REL)                        0x90d0
 0x00000012 (RELSZ)                      48 (bytes)
 0x00000013 (RELENT)                     8 (bytes)
 0x00000000 (NULL)                       0x0

  ************************************************************************
可以看出thttpd以来libcrypt和libc lib,将arm-linux-tools的lib目录下的相应库文件拷贝至target的/lib目录
如果依然出现错误,将libnss_files lib拷贝至target的/lib目录,bean个人认为是前两个库依赖libnss_files[未验证]。

当然, 也可以直接使用静态库文件

cd thttpd-2.25b/

vi Makefile
指定静态链接二进制文件
LDFLAGS = static

重新编译


6,无法解析cgi.
A:检查thttpd的配置,默认配置时打开了chroot,此时不支持运行cgi
  修改thttpd.conf,将chroot注释掉,并保证user/logfile/pidfile/port/cgipat的有效设置

 

参考:

http://www.4ucode.com/Study/Topic/1594382


  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值