ARM-Linux下WEB服务器Boa的移植、配置和运行测试

Linux下使用的轻量级WEB服务器主要有:lighttpd、thttpd、shttpd和boa等等,而Boa是使用最为广泛的轻量级WEB服务器之一(当然,阿帕奇是世界使用排名第一的Web服务器软件)。Boa是一种非常小巧的Web服务器,其可执行代码只有大约60KB左右。作为一种单任务Web服务器,Boa只能依次完成用户的请求,而不会fork出新的进程来处理并发连接请求。但Boa支持CGI,能够为CGI程序fork出一个进程来执行,Boa的设计目标是速度和安全。

工具链为:arm-hismall-linux-gcc,海思平台。


一、Boa移植

1.下载boa-0.94.13.tar.gz

http://download.csdn.net/detail/huangminqiang201209/5769107

2.编译

[root@localhostweb]#tar xzvf boa-0.94.13.tar.gz

[root@localhostweb]#cd boa-0.94.13

[root@localhostboa-0.94.13]#cd src/

[root@localhostsrc]#./configure//生成Makefile

[root@localhostsrc]#vi Makefile

30:CC = gcc

31:CPP = gcc -E

该为:

CC= arm-hismall-linux-gcc

CPP= arm-hismall-linux-gcc -E

[root@localhostsrc]# vi compat.h

120:#define TIMEZONE_OFFSET(foo) foo##->tm_gmtoff //##的作用是把2个参数合并到一起

修改成

#defineTIMEZONE_OFFSET(foo) (foo)->tm_gmtoff

[root@localhostsrc]# vi log.c

72:if (dup2(error_log, STDERR_FILENO) == -1) {

DIE("unable to dup2 the errorlog");

}

为(即屏蔽):

/*if (dup2(error_log, STDERR_FILENO) == -1){

DIE("unable to dup2 the errorlog");

}*/

[root@localhostsrc]#vi boa.c

73:if (dup2(error_log, STDERR_FILENO) == -1) {

DIE("unable to dup2 the errorlog");

}

为(即屏蔽):

/*if (dup2(error_log, STDERR_FILENO) == -1){

DIE("unable to dup2 the errorlog");

}*/

211:if (passwdbuf == NULL) {

DIE(”getpwuid”);

}

if (initgroups(passwdbuf->pw_name,passwdbuf->pw_gid) == -1) {

DIE(”initgroups”);

}

为(即屏蔽):

#if 0

if (passwdbuf == NULL) {

DIE(”getpwuid”);

}

if (initgroups(passwdbuf->pw_name,passwdbuf->pw_gid) == -1) {

DIE(”initgroups”);

}

#endif

[root@localhostsrc]# make

[root@localhostsrc]#arm-hismall-linux-strip boa//去除调试信息减小体积。可选

二、配置Boa

1boa.conf

Boa需要在/etc目录下建立一个boa目录,里面放入Boa的主要配置文件boa.conf。在boa-0.94.13目录下已有一个示例boa.conf,可以在其基础上进行修改。

[root@localhost src]# cd ..

[root@localhost boa-0.94.13]# vi boa.conf

(1)Group的修改

修改Group nogroup为Group 0 //开发板上有的组,设为0

(2)user的修改

修改User nobody为User 0

(3)Alias的修改

修改ScriptAlias /cgi-bin/ /usr/lib/cgi-bin/ 为 Alias /cgi-bin/ /www/cgi-bin/

(4)DoucmentRoot的修改

修改DoucmentRoot /var/www 为DoucmentRoot /www

(5)ServerName的设置

修改#ServerName www.your.org.here为 ServerName www.your.org.here,否则会出现错误“gethostbyname::No such file or directory”

(6)AccessLog修改

修改AccessLog/var/log/boa/access_log为#AccessLog /var/log/boa/access_log,否则会出现错误提示:“unable to dup2 the errorlog: Bad file deor”

2)开发板etc配置

/etc $mount-t nfs -o nolock 192.168.1.211:/work/nfs /nfs

/etc $cp/nfs/mime.types .

/etc $mkdir boa

/etc $cd/boa

/etc/boa $ cp /nfs/web/boa-0.94.13/boa.conf.

/etc/boa $cp/nfs/web/boa-0.94.13/src/boa .

/etc/boa $mkdir /www

/etc/boa $ mkdir -p/www/cgi-bin

3)运行boa

/etc/boa $./boa

[16/Jul/2013:19:22:51+0000] boa: server version Boa/0.94.13

[16/Jul/2013:19:22:51+0000] boa: server built Jul 17 2013 at 10:38:13.

[16/Jul/2013:19:22:51+0000] boa: starting server pid=718, port 80

三、Boa测试

1)静态网页测试

将静态网页存入根文件系统的/www目录下(/1.jpg即为/www/1.jpg)
/www $ cat index.html
<html>
<body>

<h1>My First Heading </h1>
<p>This is a paragraph</p>
<h2>My First Heading </h2>
<a href="http://www.baidu.com">This is a link</a>
<img src="/1.jpg" width="104" height="142" />

</body>
</html>

直接在浏览器中输入开发板的IP地址(比如我的是http://192.168.1.66) ,出现如下画面。静态HTML调试成功。


2)CGI功能测试

1)生成GCI可执行程序

[root@localhost for_test]# cat helloworldCGI.c

#include<stdio.h>

#include<stdlib.h>

int main(void)

{

printf("Content-type: text/html\n\n");

printf("<html>\n");

printf("<head><title>CGI Output</title></head>\n");

printf("<body>\n");

printf("<h1>Hello,world.</h1>\n");

printf("<body>\n");

printf("</html>\n");

exit(0);

}

[root@localhost for_test]# chmod 777 helloworldCGI.c

[root@localhost for_test]# arm-hismall-linux-gcc helloworldCGI.c

2)开发板端

/etc/boa$cp /nfs/for_test/a.out /www/cgi-bin/

3)浏览器

在浏览器输入: http://192.168.1.66/cgi-bin/a.out ,网页出现 Hello,world. 调试成功!

四、参考文献

boa web服务器移植:http://blog.chinaunix.net/uid-25544300-id-3227511.html

三种嵌入式web服务器(Boa / lighttpd / shttpd)的 linux移植笔记:http://blog.chinaunix.net/uid-26921272-id-3322975.html


希望对你有所帮助


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

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

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

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值