参考文档:
https://blog.csdn.net/feit2417/article/details/84777523
1.下载boa源码
Boa Webserver主页:Boa Webserver
下载链接:http://www.boa.org/boa-0.94.13.tar.gz
下载后,解压 tar zxvf boa-0.94.13.tar.gz。
文件列表如下所示:
lkmao@ubuntu:/big/web/boa/boa-0.94.13$ ls -F -l
总用量 76
-rw-r--r-- 1 lkmao lkmao 7360 3月 22 2002 boa.conf
-rw-r--r-- 1 lkmao lkmao 20381 7月 30 2002 ChangeLog
drwxr-xr-x 3 lkmao lkmao 4096 7月 30 2002 contrib/
-rw-r--r-- 1 lkmao lkmao 966 3月 26 2002 CREDITS
drwxr-xr-x 2 lkmao lkmao 4096 7月 30 2002 docs/
drwxr-xr-x 2 lkmao lkmao 4096 7月 30 2002 examples/
drwxr-xr-x 2 lkmao lkmao 4096 7月 30 2002 extras/
-rw-r--r-- 1 lkmao lkmao 17992 1月 30 2000 Gnu_License
-rw-r--r-- 1 lkmao lkmao 606 3月 1 2002 README
drwxr-xr-x 2 lkmao lkmao 4096 7月 30 2002 src/
lkmao@ubuntu:/big/web/boa/boa-0.94.13$
进入src子目录,如下所示:
lkmao@ubuntu:/big/web/boa/boa-0.94.13/src$ ls -F --color
acconfig.h boa.c boa_lexer.l cgi_header.c config.c configure.in escape.h hash.c log.c parse.h read.c select.c timestamp.c
aclocal.m4 boa_grammar.y buffer.c check_struct_for.m4 config.h.in defines.h get.c index_dir.c Makefile.in pipe.c request.c signals.c util.c
alias.c boa.h cgi.c compat.h configure* escape.c globals.h ip.c mmap_cache.c queue.c response.c sublog.c webindex.pl*
lkmao@ubuntu:/big/web/boa/boa-0.94.13/src$
执行./configure配置编译环境
lkmao@ubuntu:/big/web/boa/boa-0.94.13/src$ ./configure
make编译源码,报错如下所示:
lkmao@ubuntu:/big/web/boa/boa-0.94.13/src$ make
gcc -g -O2 -pipe -Wall -I. -c -o util.o util.c
In file included from boa.h:50:0,
from util.c:26:
util.c: In function ‘get_commonlog_time’:
util.c:100:39: error: pasting "t" and "->" does not give a valid preprocessing token
time_offset = TIMEZONE_OFFSET(t);
^
compat.h:120:30: note: in definition of macro ‘TIMEZONE_OFFSET’
#define TIMEZONE_OFFSET(foo) foo##->tm_gmtoff
^
<builtin>: recipe for target 'util.o' failed
make: *** [util.o] Error 1
lkmao@ubuntu:/big/web/boa/boa-0.94.13/src$
修改文件compat.h,跳转到120行:
#define TIMEZONE_OFFSET(foo) (foo)->tm_gmtoff //修改成这个
//#define TIMEZONE_OFFSET(foo) foo##->tm_gmtoff //注释掉
修改后的:
修改boa.c文件,跳转到225行注释如下代码:
225 /*if (setuid(0) != -1) {
226 DIE("icky Linux kernel bug!");
227 }*/
创建boa安装目录 /boa及其子目录
lkmao@ubuntu:/big/web/boa/boa-0.94.13/src$ sudo mkdir -p /boa /boa/www /boa/cgi-bin /boa/log
lkmao@ubuntu:/big/web/boa/boa-0.94.13/src$
修改defines.h文件中的SERVER_ROOT,使其指向改动后的配置文件路径
lkmao@ubuntu:/big/web/boa/boa-0.94.13/src$ vi defines.h
跳转到30行,修改后如下所示:
29 #ifndef SERVER_ROOT
30 #define SERVER_ROOT "/boa"
31 //#define SERVER_ROOT "/etc/boa"
32 #endif
7.复制必要的文件到安装目录
lkmao@ubuntu:/big/web/boa/boa-0.94.13$ sudo cp boa.conf /boa/
lkmao@ubuntu:/big/web/boa/boa-0.94.13$ cd src/
lkmao@ubuntu:/big/web/boa/boa-0.94.13/src$ sudo cp boa /boa/
lkmao@ubuntu:/big/web/boa/boa-0.94.13/src$ sudo cp boa_indexer /boa/
lkmao@ubuntu:/big/web/boa/boa-0.94.13/src$ sudo cp /etc/mime.types /boa/
lkmao@ubuntu:/big/web/boa/boa-0.94.13/src$
8.修改boa配置文件
lkmao@ubuntu:~$ cd /boa/
lkmao@ubuntu:/boa$ su
密码:
root@ubuntu:/boa# cp boa.conf boa.conf.back
root@ubuntu:/boa# cat boa.conf.back | grep -v "#" | grep -v "^$" > boa.conf
修改boa.conf如下所示:
Port 80
User 0
Group 0
ErrorLog /boa/log/error_log
AccessLog /boa/log/access_log
DocumentRoot /boa/www
UserDir public_html
DirectoryIndex index.html
DirectoryMaker /boa/boa_indexer
KeepAliveMax 1000
KeepAliveTimeout 10
MimeTypes /boa/mime.types
DefaultType text/plain
CGIPath /bin:/usr/bin:/usr/local/bin
Alias /doc /usr/doc
ScriptAlias /cgi-bin/ /boa/cgi-bin/
9.实现HTML页面文件
(1)index.html
root@ubuntu:/boa# cd www/
root@ubuntu:/boa/www# touch index.html
root@ubuntu:/boa/www# vi index.html
<html>
<head>
</head>
<body>
<h3>this is a test!</h3><br/>
<h3>tree picture</h3><br/>
<a href="/cgi-bin/test.cgi">to cgi page</a>
</body>
</html>
(3)test.cgi
root@ubuntu:/boa/www# cd ../cgi-bin/
root@ubuntu:/boa/cgi-bin# touch test.c
root@ubuntu:/boa/cgi-bin# vi test.c
#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;
}
root@ubuntu:/boa/cgi-bin# gcc -o test.cgi test.c
root@ubuntu:/boa/cgi-bin# ls
test.c test.cgi
root@ubuntu:/boa/cgi-bin#
root@ubuntu:/boa/cgi-bin# ls
test.c test.cgi
root@ubuntu:/boa/cgi-bin# cd ..
root@ubuntu:/boa# tree
.
├── access_log
├── boa
├── boa.conf
├── boa.conf.bak
├── boa_indexer
├── cgi-bin
│ ├── test.c
│ └── test.cgi
├── log
│ ├── access_log
│ └── error_log
├── mime.types
└── www
└── index.html
3 directories, 11 files
root@ubuntu:/boa#
运行验证
在windows上测试:
下一篇:
web测试2:嵌入式移植boa