Boa服务器移植
一. 获取源码并解压源码
$ cp '/var/run/vmblock-fuse/blockdir/52c7ee05-b77c-c251-17a3-7856942e7e9e/boa-0.94.13.tar.gz' ./
linux@linux:~/BOA_SRC$ ls
boa-0.94.13.tar.gz
linux@linux:~/BOA_SRC$ ls
boa-0.94.13.tar.gz
$ tar xvf boa-0.94.13.tar.gz
boa-0.94.13/
boa-0.94.13/docs/
boa-0.94.13/docs/Makefile
boa-0.94.13/docs/boa.8
boa-0.94.13/docs/boa.texi
boa-0.94.13/docs/boa_banner.png
boa-0.94.13/CREDITS
boa-0.94.13/ChangeLog
boa-0.94.13/Gnu_License
boa-0.94.13/README
boa-0.94.13/boa.conf
boa-0.94.13/contrib/
boa-0.94.13/contrib/README.chroot.solaris
boa-0.94.13/contrib/redhat/
boa-0.94.13/contrib/redhat/boa.conf
boa-0.94.13/contrib/redhat/boa.init
boa-0.94.13/contrib/redhat/boa.logrotate
boa-0.94.13/contrib/redhat/boa.spec
boa-0.94.13/examples/
boa-0.94.13/examples/cgi-test.cgi
boa-0.94.13/examples/nph-test.cgi
boa-0.94.13/examples/resolver.pl
boa-0.94.13/extras/
boa-0.94.13/extras/alphasort.c
boa-0.94.13/extras/scandir.c
boa-0.94.13/extras/strutil.c
boa-0.94.13/src/
boa-0.94.13/src/.depend
boa-0.94.13/src/Makefile.in
boa-0.94.13/src/acconfig.h
boa-0.94.13/src/aclocal.m4
boa-0.94.13/src/alias.c
boa-0.94.13/src/boa.c
boa-0.94.13/src/boa.h
boa-0.94.13/src/boa_grammar.y
boa-0.94.13/src/boa_lexer.l
boa-0.94.13/src/buffer.c
boa-0.94.13/src/cgi.c
boa-0.94.13/src/cgi_header.c
boa-0.94.13/src/check_struct_for.m4
boa-0.94.13/src/compat.h
boa-0.94.13/src/config.c
boa-0.94.13/src/config.h.in
boa-0.94.13/src/configure
boa-0.94.13/src/configure.in
boa-0.94.13/src/defines.h
boa-0.94.13/src/escape.c
boa-0.94.13/src/escape.h
boa-0.94.13/src/get.c
boa-0.94.13/src/globals.h
boa-0.94.13/src/hash.c
boa-0.94.13/src/index_dir.c
boa-0.94.13/src/ip.c
boa-0.94.13/src/log.c
boa-0.94.13/src/mmap_cache.c
boa-0.94.13/src/parse.h
boa-0.94.13/src/pipe.c
boa-0.94.13/src/queue.c
boa-0.94.13/src/read.c
boa-0.94.13/src/request.c
boa-0.94.13/src/response.c
boa-0.94.13/src/select.c
boa-0.94.13/src/signals.c
boa-0.94.13/src/sublog.c
boa-0.94.13/src/timestamp.c
boa-0.94.13/src/util.c
boa-0.94.13/src/webindex.pl
$ ls
boa-0.94.13 boa-0.94.13.tar.gz
$ cd boa-0.94.13/
$ ls
boa.conf ChangeLog contrib CREDITS docs examples extras Gnu_License README src
二. 修改源码
-
修改compat.h
$ vi compat.h +120
-
修改defines.h
-
修改boa.c
-
修改log.c
三. 编译
3.1 生成Makefile文件
$ pwd
/home/y/boa-0.94.13/src
$ ls
acconfig.h cgi_header.o escape.h Makefile select.c
aclocal.m4 cgi.o escape.o Makefile.in select.o
alias.c check_struct_for.m4 get.c mmap_cache.c signals.c
alias.o compat.h get.o mmap_cache.o signals.o
boa config.c globals.h parse.h sublog.c
boa.c config.cache hash.c pipe.c sublog.o
boa_grammar.y config.h hash.o pipe.o timestamp.c
boa.h config.h.in index_dir.c queue.c timestamp.o
boa_indexer config.log index_dir.o queue.o util.c
boa_lexer.l config.o ip.c read.c util.o
boa.o config.status ip.o read.o webindex.pl
buffer.c configure lex.yy.c request.c y.tab.c
buffer.o configure.in lex.yy.o request.o y.tab.h
cgi.c defines.h log.c response.c y.tab.o
cgi_header.c escape.c log.o response.o
$ ./configure
3.2 编译
$make
3.3 有可能产生的问题
- 问题1
$ make
yacc -d boa_grammar.y
make: yacc: Command not found
Makefile:59: recipe for target 'y.tab.c' failed
make: *** [y.tab.c] Error 127
解决方法
$ sudo apt-get install bison
- 问题2
$ make
yacc -d boa_grammar.y
gcc -g -O2 -pipe -Wall -I. -c -o y.tab.o y.tab.c
y.tab.c: In function ‘yyparse’:
y.tab.c:1191:16: warning: implicit declaration of function ‘yylex’ [-Wimplicit-function-declaration]
yychar = yylex ();
^~~~~
lex boa_lexer.l
make: lex: Command not found
Makefile:62: recipe for target 'lex.yy.c' failed
make: *** [lex.yy.c] Error 127
解决方法
$ sudo apt-get install flex
3.4 最终生成两个可执行文件 - boa boa_indexer
$ make
lex boa_lexer.l
gcc -g -O2 -pipe -Wall -I. -c -o lex.yy.o lex.yy.c
boa_lexer.l: In function ‘yylex’:
boa_lexer.l:82:2: warning: implicit declaration of function ‘yyerror’; did you mean ‘perror’? [-Wimplicit-function-declaration]
yyerror("unterminated string constant");
^~~~~~~
perror
At top level:
lex.yy.c:1330:16: warning: ‘input’ defined but not used [-Wunused-function]
static int input (void)
^~~~~
lex.yy.c:1287:17: warning: ‘yyunput’ defined but not used [-Wunused-function]
static void yyunput (int c, char * yy_bp )
^~~~~~~
gcc -g -O2 -pipe -Wall -I. -c -o alias.o alias.c
gcc -g -O2 -pipe -Wall -I. -c -o boa.o boa.c
gcc -g -O2 -pipe -Wall -I. -c -o buffer.o buffer.c
gcc -g -O2 -pipe -Wall -I. -c -o cgi.o cgi.c
gcc -g -O2 -pipe -Wall -I. -c -o cgi_header.o cgi_header.c
gcc -g -O2 -pipe -Wall -I. -c -o config.o config.c
gcc -g -O2 -pipe -Wall -I. -c -o escape.o escape.c
gcc -g -O2 -pipe -Wall -I. -c -o get.o get.c
get.c: In function ‘index_directory’:
get.c:509:5: warning: ignoring return value of ‘chdir’, declared with attribute warn_unused_result [-Wunused-result]
chdir(server_root);
^~~~~~~~~~~~~~~~~~
gcc -g -O2 -pipe -Wall -I. -c -o hash.o hash.c
gcc -g -O2 -pipe -Wall -I. -c -o ip.o ip.c
gcc -g -O2 -pipe -Wall -I. -c -o log.o log.c
gcc -g -O2 -pipe -Wall -I. -c -o mmap_cache.o mmap_cache.c
mmap_cache.c: In function ‘find_mmap’:
mmap_cache.c:70:9: warning: cast from pointer to integer of different size [-Wpointer-to-int-cast]
if ((int) m == -1) {
^
gcc -g -O2 -pipe -Wall -I. -c -o pipe.o pipe.c
gcc -g -O2 -pipe -Wall -I. -c -o queue.o queue.c
gcc -g -O2 -pipe -Wall -I. -c -o read.o read.c
gcc -g -O2 -pipe -Wall -I. -c -o request.o request.c
request.c: In function ‘get_request’:
request.c:84:17: warning: pointer targets in passing argument 3 of ‘accept’ differ in signedness [-Wpointer-sign]
&remote_addrlen);
^
In file included from /usr/include/netinet/in.h:23:0,
from /usr/include/netdb.h:27,
from boa.h:41,
from request.c:25:
/usr/include/x86_64-linux-gnu/sys/socket.h:232:12: note: expected ‘socklen_t * restrict {aka unsigned int * restrict}’ but argument is of type ‘int *’
extern int accept (int __fd, __SOCKADDR_ARG __addr,
^~~~~~
request.c:137:55: warning: passing argument 3 of ‘getsockname’ from incompatible pointer type [-Wincompatible-pointer-types]
if (getsockname(fd, (struct sockaddr *) &salocal, &len) != 0) {
^
In file included from /usr/include/netinet/in.h:23:0,
from /usr/include/netdb.h:27,
from boa.h:41,
from request.c:25:
/usr/include/x86_64-linux-gnu/sys/socket.h:116:12: note: expected ‘socklen_t * restrict {aka unsigned int * restrict}’ but argument is of type ‘size_t * {aka long unsigned int *}’
extern int getsockname (int __fd, __SOCKADDR_ARG __addr,
^~~~~~~~~~~
request.c:171:64: warning: passing argument 5 of ‘getsockopt’ from incompatible pointer type [-Wincompatible-pointer-types]
(conn->fd, SOL_SOCKET, SO_SNDBUF, &system_bufsize, &len) == 0
^
In file included from /usr/include/netinet/in.h:23:0,
from /usr/include/netdb.h:27,
from boa.h:41,
from request.c:25:
/usr/include/x86_64-linux-gnu/sys/socket.h:208:12: note: expected ‘socklen_t * restrict {aka unsigned int * restrict}’ but argument is of type ‘size_t * {aka long unsigned int *}’
extern int getsockopt (int __fd, int __level, int __optname,
^~~~~~~~~~
request.c: In function ‘free_request’:
request.c:361:9: warning: ignoring return value of ‘read’, declared with attribute warn_unused_result [-Wunused-result]
read(req->fd, buf, 32768);
^~~~~~~~~~~~~~~~~~~~~~~~~
gcc -g -O2 -pipe -Wall -I. -c -o response.o response.c
gcc -g -O2 -pipe -Wall -I. -c -o select.o select.c
gcc -g -O2 -pipe -Wall -I. -c -o signals.o signals.c
signals.c: In function ‘sigsegv’:
signals.c:103:5: warning: ignoring return value of ‘chdir’, declared with attribute warn_unused_result [-Wunused-result]
chdir(tempdir);
^~~~~~~~~~~~~~
signals.c: In function ‘sigbus’:
signals.c:119:5: warning: ignoring return value of ‘chdir’, declared with attribute warn_unused_result [-Wunused-result]
chdir(tempdir);
^~~~~~~~~~~~~~
signals.c: In function ‘sigterm_stage2_run’:
signals.c:144:5: warning: ignoring return value of ‘chdir’, declared with attribute warn_unused_result [-Wunused-result]
chdir(tempdir);
^~~~~~~~~~~~~~
signals.c: In function ‘sigint’:
signals.c:193:5: warning: ignoring return value of ‘chdir’, declared with attribute warn_unused_result [-Wunused-result]
chdir(tempdir);
^~~~~~~~~~~~~~
gcc -g -O2 -pipe -Wall -I. -c -o util.o util.c
gcc -g -O2 -pipe -Wall -I. -c -o sublog.o sublog.c
gcc -g -O2 -pipe -Wall -I. -c -o timestamp.o timestamp.c
gcc -o boa y.tab.o lex.yy.o 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 read.o request.o response.o select.o signals.o util.o sublog.o timestamp.o -g
gcc -g -O2 -pipe -Wall -I. -c -o index_dir.o index_dir.c
gcc -o boa_indexer index_dir.o escape.o -g
$ ls
acconfig.h cgi_header.o escape.h Makefile select.c
aclocal.m4 cgi.o escape.o Makefile.in select.o
alias.c check_struct_for.m4 get.c mmap_cache.c signals.c
alias.o compat.h get.o mmap_cache.o signals.o
boa config.c globals.h parse.h sublog.c
boa.c config.cache hash.c pipe.c sublog.o
boa_grammar.y config.h hash.o pipe.o timestamp.c
boa.h config.h.in index_dir.c queue.c timestamp.o
boa_indexer config.log index_dir.o queue.o util.c
boa_lexer.l config.o ip.c read.c util.o
boa.o config.status ip.o read.o webindex.pl
buffer.c configure lex.yy.c request.c y.tab.c
buffer.o configure.in lex.yy.o request.o y.tab.h
cgi.c defines.h log.c response.c y.tab.o
cgi_header.c escape.c log.o response.o
四. 部署boa的运行目录
4.1 路径和define.h的一致
4.2 创建目录
$mkdir www
$mkdir cgi-bin
$mkdir log
4.3 拷贝文件
boa boa_indexer boa.conf mime.types
test.cgi
index.html
image.jpg
4.4 最终的目录结构
4.5 修改boa(boa.conf)的配置文件
Port 80
User 0
Group 0
#Listen 192.68.0.5
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/
五. 测试
5.1 终端运行
$ sudo ./boa
[05/Jan/2021:03:05:30 +0000] boa: server version Boa/0.94.13
[05/Jan/2021:03:05:30 +0000] boa: server built Jan 5 2021 at 09:25:30.
[05/Jan/2021:03:05:30 +0000] boa: starting server pid=8158, port 80
5.2 打开火狐浏览器,输入回环地址
浏览器中出现测试的页面,表示boa服务器正常运行
三. 结束boa进程
-
查看进程号
ps auc|grep "boa"
$ ps aux|grep "boa" linux 2319 0.0 0.9 133008 10016 ? Sl 09:01 0:00 /usr/lib/i386-linux-gnu/indicator-keyboard-service --use-gtk root 4613 0.0 0.0 2476 708 pts/0 S 09:45 0:00 ./boa linux 4745 0.0 0.0 4684 820 pts/0 S+ 10:37 0:00 grep --color=auto boa
-
结束boa进程
kill -9 进程号
kill -9 4613
-
重新运行boa
sudo ./boa