移植thttpd嵌入式web服务器

本文详细介绍了如何在嵌入式平台成功移植thttpd服务器,包括交叉编译、安装配置、动态库依赖、添加CGI支持等步骤。遇到的错误403被归因于非CGI文件被误认为CGI文件,通过修改文件权限得以解决。

摘要生成于 C知道 ,由 DeepSeek-R1 满血版支持, 前往体验 >

大家都知道,thttpd是一款非常优秀的适用于嵌入式平台的web服务器,网上也有一些教我们如何移植的文章。对于一般情况可能都适用,但是偏偏到了我这就不能一次成功。

总的算起来,我前几天开始装,基本上安装下面的步骤:(参考来自:tekkman.cublog.cn )

1载并解压

下载地址为:

http://www.acme.com/software/thttpd/我下载的是最新的2.25b

2 交叉thttpd

[tekkamanninja@Tekkaman-Ninja source]$cd thttpd-2.25b
[tekkamanninja@Tekkaman-Ninja thttpd-2.25b]$CC=/home/tekkamanninja/working/gcc4.1.1/gcc-4.1.1-glibc-2.3.2/arm-9tdmi-linux-gnu/bin/arm-9tdmi-linux-gnu-gcc./configure –host=arm-9tdmi-linux-gnu
[tekkamanninja@Tekkaman-Ninja thttpd-2.25b]$make

3 安装与配置
3.1 拷贝thttpd二进制可执行文件到根文件系统/usr/sbin/目录中

[tekkamanninja@Tekkaman-Ninja thttpd-2.25b]$cp thttpd/home/tekkamanninja/working/nfs/rootfs/usr/sbin/



3.2 拷贝thttpd配置文件

[tekkamanninja@Tekkaman-Ninja thttpd-2.25b]$cp contrib/redhat-rpm/thttpd.conf/home/tekkamanninja/working/nfs/rootfs/etc/


3.3在开发板上为thttpd创建一个独立的用户:httpd,并用此用户创建httpd服务的根目录html

[root@/root]#adduser httpd
Changing passwordforhttpd
Enter thenewpassword(minimum of 5,maximum of 8 characters)
Please use a combination of upperandlowercaselettersandnumbers.
Enternewpassword:
Bad password:tooshort.

Warning:weak password(continuing).
Re-enternewpassword:
passwd[786]:passwordfor`httpd' changed by user `root'
Password changed.
[root@/root]#exit
process'-/bin/login'(pid 787)exited.Scheduling itforrestart.
starting pid 790,tty'':'/bin/login'

192.168.1.2 login:httpd
Password:

Processing/etc/profile...
Setsearchlibrary path in/etc/profile
Setuser path in/etc/profile
SetPS1 in/etc/profile
Done

[httpd@/home/httpd]$mkdir html

3.4 拷贝测试网页到httpd服务的根目(可选,测试之用):

[tekkamanninja@Tekkaman-Ninja thttpd-2.25b]$cp index.html/home/tekkamanninja/working/nfs/rootfs/home/httpd/html/

我是动态编译所以查看一下需要的动态库

[tekkamanninja@Tekkaman-Ninja thttpd-2.25b]$/home/tekkamanninja/working/gcc4.1.1/gcc-4.1.1-glibc-2.3.2/arm-9tdmi-linux-gnu/bin/arm-9tdmi-linux-gnu-readelf-d thttpd

Dynamic section at offset 0x12014 contains 21 entries:
Tag Type Name/Value
0x00000001(NEEDED)Shared library:[libcrypt.so.1]
0x00000001(NEEDED)Shared library:[libc.so.6]
0x0000000c(INIT)0x9548
0x0000000d(FINI)0x16564
0x00000004(HASH)0x8128
0x00000005(STRTAB)0x8c14
0x00000006(SYMTAB)0x8494
0x0000000a(STRSZ)1066(bytes)
0x0000000b(SYMENT)16(bytes)
0x00000015(DEBUG)0x0
0x00000003(PLTGOT)0x220e4
0x00000002(PLTRELSZ)872(bytes)
0x00000014(PLTREL)REL
0x00000017(JMPREL)0x91e0
0x00000011(REL)0x91a0
0x00000012(RELSZ)64(bytes)
0x00000013(RELENT)8(bytes)
0x6ffffffe(VERNEED)0x9130
0x6fffffff(VERNEEDNUM)2
0x6ffffff0(VERSYM)0x903e
0x00000000(NULL)0x0

虽然这里只列出了需要libcryptlibc这两个动态库,但是想要运行thttpd还需要libnss_files动态库,具体原因请看:http://www.jollen.org/blog/2006/10/library_dependency_1.html

[tekkamanninja@Tekkaman-Ninja thttpd-2.25b]$cp-d/home/tekkamanninja/working/gcc4.1.1/gcc-4.1.1-glibc-2.3.2/arm-9tdmi-linux-gnu/arm-9tdmi-linux-gnu/lib/libnss_files*/home/tekkamanninja/working/nfs/rootfs/lib/


你可以在启动文件里增加thttpd的启动命令:thttpd -C /etc/thttpd.conf

注意只有root有启动权限!

4、增加对CGI的支持

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

#Thissection overrides defaults
dir=/home/httpd/html
#chroot
#屏蔽chroot是为了运行动态编译的CGI
user=httpd#default=nobody
logfile=/var/log/thttpd.log
pidfile=/var/run/thttpd.pid
#Thissection _documents_ defaults in effect
port=81
#port参数用于更改端口号(可不改,若还运行了别的WEB服务器,则需用不同端口)
#nosymlink#default=!chroot
#symlinks
#novhost
cgipat=/cgi-bin/*
#声明CGI程序的目录,是以dir为根目录的路径
# nothrottles
# host=0.0.0.0
# charset=iso-8859-1

移植完成,可以测试了(只需在WEB浏览器中键入开发板的IP地址即可)

到了这里,当我输入目标板ip时,问题出现了:

错误:403 forbidden.
The requested URL '/' resolves to a file which is marked executable but is not a CGI file;

retrieving it is forbidden.

网上也有很多说法,可是好像都不适用于我这里,千辛万苦才找到以下解释:
原因:由于linux文件系统的权限问题,非cgi的文件请使用chmod -x去掉其可执行权限,否则web服务器

会认为它是cgi ( 比如index.html这样的文件 )

按如下解决

解决:chmod -x dir../index.html ,其中,dir..表示index.html的目录

到这,问题才算解决了,下一步该测试CGI了。。。

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值