Boa服务器移植到嵌入式开发板上

Boa服务器移植:

<一> Boa的编译

1.从 http://www.boa.org 下载 Boa 服务器的最新版Latest Released Version (0.94.13):boa-0.94.13.tar.gz。
2. 解压:tar -xvf boa-0.94.13.tar.gz
3. 进入解压后的文件夹 boa-0.94.13内部的 src文件夹,对源文件进行如下修改
a、由于arm-linux-gcc 编译器版本过高,对语法的支持有一些改变,所以需要修改compat.h中的源(120行) 处
#define TIMEZONE_OFFSET(foo) foo##->tm_gmtoff   修改为 #define TIMEZONE_OFFSET(foo) foo->tm_gmtoff
不然在编译的时候会提示如下错误:
util.c: 100: 1: pasting “t” and “->” does not give a valid preprocessing token make: [util.o] Error1

b、将boa.c 文件其中三行的文件注释掉源(226行) 注释掉

if (setuid(0) != -1) {
DIE(”icky Linux kernel bug!”);
}
/*
if (setuid(0) != -1) {
DIE(”icky Linux kernel bug!”);
}
*/
否则,但以root权限启动boa服务器的时候,会出现以下错误:boa.c:226 - icky Linux kernel bug!:

4. 然后生成Makefile:./configure
5. 修改生成的Makefile:默认生成的Makefile针对x86平台,我们的目标是针对嵌入式平台,所以需要修改编译器.
更改Makefile文件:vi Makefife
源 改为
CC = gcc
CPP = gcc -E
CC = arm-linux-gcc
CPP = arm-linux-gcc -E

6. 在当前目录下编译Boa源文件: make
7. 将生成好的boa可执行文件去掉冗余信息: arm-linux-strip boa.



<二> 将Boa移植到开发板中

1. 修改boa.conf配置文件:
(1) 修改port端口,用来设置服务器监听的端口:
# Port: The port Boa runs on. The default port for http servers is 80.
# If it is less than 1024, the server must be started as root.
Port 80
(2) 注释监听IP地址:默认监听该主机上的所有IP地址
#Listen 192.68.0.5
(3) 修改user和Group 启动的UID和GID,使其以root身份启动
# User: The name or UID the server should run as.
# Group: The group name or GID the server should run as.
User root
Group root
(4) 修改DocumentRoot地址,即客户端要显示的HTML页面存放位置
# DocumentRoot: The root directory of the HTML documents.
# Comment out to disable server non user files.
DocumentRoot /var/www
(5) 修改输入网页输入主机IP时要显示的页面:这里设为index.html
# DirectoryIndex: Name of the file to use as a pre-written HTML
# directory index. Please MAKE AND USE THESE FILES. On the
# fly creation of directory indexes can be _slow_.
# Comment out to always use DirectoryMaker
DirectoryIndex index.html
(6) 修改CGI程序存放的位置:以http://IP/cgi-bin/cginame 的方式运行cgi 程序时将在/usr/local/boa/cgi-bin 目录下寻找该程序
# ScriptAlias: Maps a virtual path to a directory for serving scripts
# Example: ScriptAlias /htbin/ /www/htbin/
ScriptAlias /cgi-bin/ /var/www/cgi-bin/
2. 将配置文件boa.conf 移动到开发板的 /etc/boa/ 目录下。
3. 创建/var/log/boa/ 目录,这样Boa服务器启动时会在该目录下创建日志文件。
4. 将Linux系统上/etc/mime.types 文件复制到开发板的/etc 目录下,否则Boa服务器启动不起来。
5. 将生成的boa文件移植到嵌入式板中的/sbin目录下并更改脚本文件 /etc/init.d/rcS, 新增一行: /sbin/boa ,确保boa服务器随系统上电自启动。


这里一定要注意:有时候boa服务器并不能随系统启动,运行 /sbin/boa 命令会提示:
gethostbyname:: Success
这种情况下要修改boa.conf 文件
    将
#ServerName  www.your.org.here    
改为      
ServerName  www.your.org.here
即去掉注释即可

备注:注意红色标记处,以免出错,
配置文件中出现的目录或文件不存在时手动创建 ! ! !



 <三> 测试Boa服务器:

1. 静态页面测试:
(将该html文件命名为index.html,放在配置文件指定目录下,我这里为 /var/www )
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml">
<head>
<meta http-equiv="Content-Type" content="text/html; charset=utf-8" />
<title>Boa 静态网页测试</title>
</head>
<body>
<h1> Welcome to Boa sever! </h1>
</body>
</html>

2. CGI  程序测试:
(该程序采用arm-linux-gcc 编译,完成后重命名为xxx.cgi,放在配置文件指定路径,我这里为 /var/www/cgi-bin/ 下)
#include <stdio.h>
int main()
{
printf("Content-type: text/html\n\n");
printf("<html>\n");
printf("<head>\n");
printf("<title>CGI Output</title>\n");
printf("</head>\n");
printf("<body>");
printf("<h1> Hello, world. </h1>");
printf("</body>");
printf("</html>\n");
return 0;
}


至此,Boa服
务器移植完成。
  • 0
    点赞
  • 9
    收藏
    觉得还不错? 一键收藏
  • 4
    评论

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

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

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值