BOA服务器移植

BOA服务器移植

环境:ARM架构 ubuntu20

开发板: 华清远见A9

源码下载

http://www.boa.org/

News! (last updated 23 February 2005)

Latest Released Version (0.94.13) here (signature here)— 下载地址

解压源码

tar -xvf boa-0.94.13.tar.gz

进入源码目录下:

cd boa-0.94.14rc21/

执行configure

在源码目录下配置与编译。执行

./configure

这是根据 configure.in 文件进行一系列的配置,生成 config.status,configure,和 Makefile 文件。

jarvis@siri:/boa-0.94.14rc21$ ./configure
checking build system type... ./config.guess: unable to guess system type

This script, last modified 2004-03-12, has failed to recognize
the operating system you are using. It is advised that you
download the most up to date version of the config scripts from

    ftp://ftp.gnu.org/pub/gnu/config/

If the version you run (./config.guess) is already up to date, please
send the following data and any information you think might be
pertinent to  in order to provide the needed
information to handle your system.

config.guess timestamp = 2004-03-12

uname -m = aarch64
uname -r = 5.4.0-148-generic
uname -s = Linux
uname -v = #165-Ubuntu SMP Tue Apr 18 08:52:58 UTC 2023

/usr/bin/uname -p = aarch64
/bin/uname -X     =

hostinfo               =
/bin/universe          =
/usr/bin/arch -k       =
/bin/arch              = aarch64
/usr/bin/oslevel       =
/usr/convex/getsysinfo =

UNAME_MACHINE = aarch64
UNAME_RELEASE = 5.4.0-148-generic
UNAME_SYSTEM  = Linux
UNAME_VERSION = #165-Ubuntu SMP Tue Apr 18 08:52:58 UTC 2023
configure: error: cannot guess build type; you must specify one

看了一下需要去他提供的网站更新config.guess

进入网站ftp.gnu.org/pub/gnu/config/

查看README

得到了github的URL

http://git.savannah.gnu.org/gitweb/?p=config.git;a=blob_plain;f=config.guess;hb=HEAD

执行命令从git下载config.guess

**/boa-0.94.14rc21**$ wget -O config.guess "http://git.savannah.gnu.org/gitweb/?p=config.git;a=blob_plain;f=config.guess;hb=HEAD"

再次执行./configure

在这里插入图片描述

编译通过

进入源码目录下的 src 目录:

cd src/

修改src目录下的defines.h

#define SERVER_ROOT "/etc/boa" 
/* 修改为 */
#define SERVER_ROOT "/boa"
//(这样 boa 程序启动时会在/boa目录下寻找boa.conf配置文件,并且将/boa文件夹作为服务器的根目录)。

修改Makefile

jarvis@siri:/boa-0.94.14rc21/src$ arm-none-linux-gnueabihf-gcc --version
arm-none-linux-gnueabihf-gcc (GNU Toolchain for the A-profile Architecture 9.2-2019.12 (arm-9.10)) 9.2.1 20191025
Copyright © 2019 Free Software Foundation, Inc.
本程序是自由软件;请参看源代码的版权声明。本软件没有任何担保;
包括没有适销性和某一专用目的下的适用性担保。

这是我用的交叉编译器的版本
交叉编译器官网
一下是makefile修改的内容

CC = gcc
CPP = gcc -E
CC = arm-none-linux-gnueabihf-gcc
CPP = arm-none-linux-gnueabihf-gcc -E

执行Makefile

jarvis@siri:/boa-0.94.14rc21/src$ make
arm-none-linux-gnueabihf-gcc  -g -O2 -pipe -Wall -I. -I.  -c -o alias.o alias.c
arm-none-linux-gnueabihf-gcc  -g -O2 -pipe -Wall -I. -I.  -c -o boa.o boa.c
arm-none-linux-gnueabihf-gcc  -g -O2 -pipe -Wall -I. -I.  -c -o buffer.o buffer.c
arm-none-linux-gnueabihf-gcc  -g -O2 -pipe -Wall -I. -I.  -c -o cgi.o cgi.c
cgi.c: 在函数‘init_cgi’中:
cgi.c:420:9:警告:this ‘for’ clause does not guard... [-Wmisleading-indentation]
  420 |for (i = 0; i < req->cgi_env_index; ++i)
      |^~~
cgi.c:422:13:附注:...this statement, but the latter is misleadingly indented as if it were guarded by the ‘for’
  422 |fprintf(stderr, "%s - environment variable for cgi: \"%s\"\n",
      |^~~~~~~
arm-none-linux-gnueabihf-gcc  -g -O2 -pipe -Wall -I. -I.  -c -o cgi_header.o cgi_header.c
arm-none-linux-gnueabihf-gcc  -g -O2 -pipe -Wall -I. -I.  -c -o config.o config.c
arm-none-linux-gnueabihf-gcc  -g -O2 -pipe -Wall -I. -I.  -c -o escape.o escape.c
arm-none-linux-gnueabihf-gcc  -g -O2 -pipe -Wall -I. -I.  -c -o get.o get.c
arm-none-linux-gnueabihf-gcc  -g -O2 -pipe -Wall -I. -I.  -c -o hash.o hash.c
arm-none-linux-gnueabihf-gcc  -g -O2 -pipe -Wall -I. -I.  -c -o ip.o ip.c
arm-none-linux-gnueabihf-gcc  -g -O2 -pipe -Wall -I. -I.  -c -o log.o log.c
arm-none-linux-gnueabihf-gcc  -g -O2 -pipe -Wall -I. -I.  -c -o mmap_cache.o mmap_cache.c
arm-none-linux-gnueabihf-gcc  -g -O2 -pipe -Wall -I. -I.  -c -o pipe.o pipe.c
arm-none-linux-gnueabihf-gcc  -g -O2 -pipe -Wall -I. -I.  -c -o queue.o queue.c
arm-none-linux-gnueabihf-gcc  -g -O2 -pipe -Wall -I. -I.  -c -o range.o range.c
arm-none-linux-gnueabihf-gcc  -g -O2 -pipe -Wall -I. -I.  -c -o read.o read.c
arm-none-linux-gnueabihf-gcc  -g -O2 -pipe -Wall -I. -I.  -c -o request.o request.c
arm-none-linux-gnueabihf-gcc  -g -O2 -pipe -Wall -I. -I.  -c -o response.o response.c
arm-none-linux-gnueabihf-gcc  -g -O2 -pipe -Wall -I. -I.  -c -o signals.o signals.c
arm-none-linux-gnueabihf-gcc  -g -O2 -pipe -Wall -I. -I.  -c -o util.o util.c
arm-none-linux-gnueabihf-gcc  -g -O2 -pipe -Wall -I. -I.  -c -o sublog.o sublog.c
arm-none-linux-gnueabihf-gcc  -g -O2 -pipe -Wall -I. -I.  -c -o select.o select.c
arm-none-linux-gnueabihf-gcc  -g -O2 -pipe -Wall -I. -I.  -c -o timestamp.o timestamp.c
arm-none-linux-gnueabihf-gcc  -o boa alias.o boa.o buffer.o cgi.o cgi_header.o config.o escape.o get.o hash.o ip.o log.o mm
ap_cache.o pipe.o queue.o range.o read.o request.o response.o signals.o util.o sublog.o select.o timestamp.o -g
arm-none-linux-gnueabihf-gcc  -g -O2 -pipe -Wall -I. -I.  -c -o index_dir.o index_dir.c
arm-none-linux-gnueabihf-gcc  -o boa_indexer index_dir.o escape.o -g

有错误到cgi.c的文件下把420行for循环自动缩进一下,警告解决

arm-none-linux-gnueabihf-gcc  -g -O2 -pipe -Wall -I. -I.  -c -o cgi.o cgi.c
arm-none-linux-gnueabihf-gcc  -g -O2 -pipe -Wall -I. -I.  -c -o timestamp.o timestamp.c
arm-none-linux-gnueabihf-gcc  -o boa alias.o boa.o buffer.o cgi.o cgi_header.o config.o escape.o get.o hash.o ip.o log.o mmap_cache.o pipe.o queue.o range.o read.o request.o response.o signals.o util.o sublog.o select.o timestamp.o -g

修改boa.conf

重新指定一些文件的生成路径,因为重新指定这些路径后会帮助我们深刻的理解关于 boa 服务器 的工作机制

几乎全部指定到 boa 的目录下,这样方便我们进行管理

在examples目录下找到boa.conf修改部分内容

Port 80
User 0
Group 0
# bind 调用的 IP 地址,一般注释掉,表明绑定到 INADDR_ANY,通配于服务器的所有 IP 地址 
#Listen 192.68.0.5
##### error_log 和 access_log 会自动生成,只要指定生成路径就可以了。
ErrorLog /boa/log/error_log
AccessLog /boa/log/access_log
##### 存放 HTML 文件的根路径
DocumentRoot /boa/www
UserDir public_html
##### 默认页面,若之输入 http://127.0.0.1/则会自动返回给浏览器默认页面 index.html
DirectoryIndex index.html
##### 保持默认
DirectoryMaker /boa/boa_indexer //被修改
KeepAliveMax 1000
KeepAliveTimeout 10
MimeTypes /boa/mime.types//被修改
DefaultType text/plain
#####指定传给 cgi 程序的 PATH 环境变量
CGIPath /bin:/usr/bin:/usr/local/bin
#####保持默认
Alias /doc /usr/doc
#####如果输入 http://127.0.0.1/cgi-bin/test.cgi, 则 boa 服务器会到/boa/cgi-bin 中寻找 test.cgi 程序。
ScriptAlias /cgi-bin/ /boa/cgi-bin/

建立测试页面

  1. index.html,将 index.html 放在/boa/www 目录下

    <html>
    	<body>
    		<h3>this is a test!</h3><br/>
    		<img src="image.jpg"/>
    		<h3>tree picture</h3><br/>
    		<a href="/cgi-bin/test.cgi">to cgi page</a> //指定了 cgi 可执行文件存放的路径,默认从/boa 的根目录开始查找
    	</body>
    </html>
    

    注意: 笔记本打开,另存为 utf-8 格式,自己添加一张图片到当前的目录下

  2. test.c 使用 arm-none-linux-gnueabihf-gcc -o test.cgi test.c将 test.c 编译生成 test.cgi,后缀为 cgi 的类型 编译后得到的 test.cgi 放在/boa/cgi-bin 目录下。

    
    **#include <stdio.h>
    
    int main(){
    		printf("Content-type:text/html\n\n"); //这句一定要加上
    		printf("<html><body>");
    		printf("<font style=\"color:red; font-size:30px;\">Hello,CGI!</font><br/>");
    		printf("<a href=\"/index.html\">return index.html</a>");
    		printf("</body></html>");
    		return 0;
    }**
    

建立安装目录

jarvis@siri:/boa-0.94.14rc21$sudo mkdir -p /boa /boa/www /boa/cgi-bin /boa/log
jarvis@siri:/boa-0.94.14rc21$sudo cp examples/boa.conf /boa
jarvis@siri:/boa-0.94.14rc21$sudo cp boa boa_indexer /boa
#将/etc/mime.types 复制到/boa 目录下
jarvis@siri:/boa-0.94.14rc21$sudo cp /etc/mime.types /boa

在这里插入图片描述

移植到开发板

将/boa 目录打包,放到开发板根目录下解压到根目录

执行

[root@farsight ]# cd boa/
[root@farsight boa]# ./boa

没有出现下面的提示,说明移植成功

在这里插入图片描述

-/bin/sh: ./boa: not found解决办法

可能会出现这样,是因为开发板里面和交叉编译器的库不一样

  1. 回到虚拟机在scr目录执行下面命令

    jarvis@siri:/boa-0.94.14rc21/src$ arm-none-linux-gnueabihf-readelf -d boa
    
    Dynamic section at offset 0xdf10 contains 25 entries:
      Tag        Type                         Name/Value
     0x00000001 (NEEDED)                     Shared library: [libc.so.6]
     0x0000000c (INIT)                       0x11758
     0x0000000d (FINI)                       0x1a038
     0x00000019 (INIT_ARRAY)                 0x2df08
     0x0000001b (INIT_ARRAYSZ)               4 (bytes)
     0x0000001a (FINI_ARRAY)                 0x2df0c
     0x0000001c (FINI_ARRAYSZ)               4 (bytes)
     0x00000004 (HASH)                       0x10190
     0x6ffffef5 (GNU_HASH)                   0x104d0
     0x00000005 (STRTAB)                     0x10f60
     0x00000006 (SYMTAB)                     0x10890
     0x0000000a (STRSZ)                      885 (bytes)
     0x0000000b (SYMENT)                     16 (bytes)
     0x00000015 (DEBUG)                      0x0
     0x00000003 (PLTGOT)                     0x2e000
     0x00000002 (PLTRELSZ)                   840 (bytes)
     0x00000014 (PLTREL)                     REL
     0x00000017 (JMPREL)                     0x11410
     0x00000011 (REL)                        0x113f0
     0x00000012 (RELSZ)                      32 (bytes)
     0x00000013 (RELENT)                     8 (bytes)
     0x6ffffffe (VERNEED)                    0x113b0
     0x6fffffff (VERNEEDNUM)                 1
     0x6ffffff0 (VERSYM)                     0x112d6
     0x00000000 (NULL)                       0x0
    

    去编译器目录下把libc.so.6动态库拷贝到开发板lib目录下

  2. 直接修改Makefile (不推荐)

    CC = arm-none-linux-gnueabihf-gcc
    CPP = arm-none-linux-gnueabihf-gcc -E 
    #修改成
    CC = arm-none-linux-gnueabihf-gcc -static
    CPP = arm-none-linux-gnueabihf-gcc -E -statics
    

    重新make 把开发板中的boa替换成刚生成的boa

测试效果

在浏览器中输入开发板的ip地址便可访问到默认的页面 index.html

点击 index.html 页面中的超链接便可访问到 cgi 测试页面,点击 test.cgi 中的超链接又可返回 index.html 页面。
在这里插入图片描述
在这里插入图片描述

参考网站

http://ask.100ask.net/question/10916

https://blog.csdn.net/yx_l128125/article/details/7418882

http://www.makeru.com.cn

  • 1
    点赞
  • 1
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值