00. Table of Contents
Article directory
01. BOA Server Overview
BOA is a very compact Web server with open source code, excellent performance, and supports CGI universal gateway interface technology. It is especially suitable for use in embedded systems.
The main function of the BOA server is to exchange information between interconnected embedded devices to achieve the purpose of monitoring embedded devices through a general network and automatically uploading feedback information to the main control device. It is based on HTTP Hypertext Transfer Protocol, and Web pages are the most basic transmission unit of Web services. The work of embedded Web services is based on the client/server computing model, which is composed of a Web browser (client) and a Web server (server), which is the famous B/S structure. The browser running with the client must first establish a connection with the embedded Web server BOA and open a socket virtual file. The creation of this file indicates that the socket connection is successfully established. Then the client browser uses the socket to GET or POST parameters. The delivery method submits a request to the Web server. After the Web browser submits the request, it is transmitted to the Web server using the HTTP protocol. After receiving the request, the web server performs transaction processing according to the request, returns an HTML file or calls an external application through CGI, and returns the processing result. The server interacts with external applications and scripts through CGI. According to the method used by the client browser when requesting, the server will collect the information provided by the client and send this part of the information to the specified CGI extension. The CGI extension processes the information and returns the results to the server, which then analyzes the information and sends the results back to the client for display on the browser.
Common Gateway Interface is a standard interface for Web server hosts to provide information services. Through the CGI interface, the Web server can obtain the information submitted by the client, transfer it to the server-side CGI program for processing, and finally return the result to the client. There are two parts that make up CGI communication: one is the HTML page, which is the actual page on the user's browser; the other is the CGI program running on the server.
The main difference from high-performance web servers such as Apache is that Boa is a single-process server, suitable for embedded single-task http servers. It is a very small web server, its executable code is only about 60KB. As a single-task web server, Boa can only complete user requests in sequence without forking a new process to handle concurrent connection requests. But Boa supports CGI and can fork a process for the CGI program to execute. Boa is designed with speed and security in mind.
02. BOA source code download
Official website: BOA source code
03. BOA transplantation
3.1 Unzip boa-0.94.13.tar.gz
deng@local:~/tools$ ls
boa-0.94.13.tar.gz
deng@local:~/tools$ tar -xvf boa-0.94.13.tar.gz
3.2 Enter the boa-0.94.13 directory
deng@local:~/tools$ cd boa-0.94.13/
deng@local:~/tools/boa-0.94.13$ ls
boa.conf ChangeLog contrib CREDITS docs examples extras Gnu_License README src
deng@local:~/tools/boa-0.94.13$
3.3 Enter the src directory
deng@local:~/tools/boa-0.94.13$ cd src/
deng@local:~/tools/boa-0.94.13/src$ ls
acconfig.h boa_grammar.y cgi.c config.c defines.h globals.h log.c pipe.c response.c timestamp.c
aclocal.m4 boa.h cgi_header.c config.h.in escape.c hash.c Makefile.in queue.c select.c util.c
alias.c boa_lexer.l check_struct_for.m4 configure escape.h index_dir.c mmap_cache.c read.c signals.c webindex.pl
boa.c buffer.c compat.h configure.in get.c ip.c parse.h request.c sublog.c
deng@local:~/tools/boa-0.94.13/src$
3.4 Set the path to search for the boa.conf configuration file when starting the server
deng@local:~/tools/boa-0.94.13/src$ pwd
/home/deng/tools/boa-0.94.13/src
deng@local:~/tools/boa-0.94.13/src$ vim defines.h +30
//修改内容如下 注释30行 添加31行
29 #ifndef SERVER_ROOT
30 //#define SERVER_ROOT "/etc/boa"
31 #define SERVER_ROOT "/home/deng/boa"
32 #endif
3.5 Generate Makefile`
deng@local:~/tools/boa-0.94.13/src$ pwd
/home/deng/tools/boa-0.94.13/src
deng@local:~/tools/boa-0.94.13/src$ ./configure
3.6 Compilation
deng@local:~/tools/boa-0.94.13/src$ pwd
/home/deng/tools/boa-0.94.13/src
deng@local:~/tools/boa-0.94.13/src$ make -j4
04. BOA deployment
4.1 Create BOA server directory
deng@local:~/boa-0.94.13/src$ mkdir -p ~/boa/bin
deng@local:~/boa-0.94.13/src$ mkdir ~/boa/log
deng@local:~/boa-0.94.13/src$ mkdir ~/boa/www
deng@local:~/boa-0.94.13/src$ mkdir ~/boa/www/cgi-bin
deng@local:~/boa-0.94.13/src$
deng@local:~/boa-0.94.13/src$ tree ~/boa
/home/deng/boa
├── bin
├── log
└── www
└── cgi-bin
4 directories, 0 files
deng@local:~/boa-0.94.13/src$
4.2 Copy the executable file boa to the /home/deng/boa/bin directory
deng@local:~/boa-0.94.13/src$ pwd
/home/deng/boa-0.94.13/src
deng@local:~/boa-0.94.13/src$ cp boa ~/boa/bin/
deng@local:~/boa-0.94.13/src$
4.3 Copy boa.conf to the ~/boa/ directory
deng@local:~/tools/boa-0.94.13$ pwd
/home/deng/tools/boa-0.94.13
deng@local:~/tools/boa-0.94.13$ cp boa.conf ~/boa/
deng@local:~/tools/boa-0.94.13$
4.4 Modify configuration file
deng@local:~/boa/boa$ pwd
/home/deng/boa
deng@local:~/boa$ vim boa.conf +48
48 #User nobody
49 #Group nogroup
50 User 0
51 Group 0
4.5 Modify the path of the log
4.6 Modify the directory of DocumentRoot
115 #DocumentRoot /var/www
116 DocumentRoot /home/deng/boa/www
4.7 Modify MimeTypes
160 #MimeTypes /etc/mime.types
161 MimeTypes /home/deng/boa/mime.types
4.8 Modify ScriptAlias
199 #ScriptAlias /cgi-bin/ /usr/lib/cgi-bin/
200 ScriptAlias /cgi-bin/ /home/deng/boa/www/cgi-bin/
4.9 Create log and copy mime file
deng@local:~$ cp /etc/mime.types ~/boa
deng@local:~$ touch ~/boa/log/error_log
deng@local:~$ touch ~/boa/log/access_log
deng@local:~$
4.10 Create index.html file
deng@local:~/boa/www$ pwd
/home/deng/boa/www
deng@local:~/boa/www$ vim index.html
The content is as follows:
<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="UTF-8">
<meta http-equiv="X-UA-Compatible" content="IE=edge">
<meta name="viewport" content="width=device-width, initial-scale=1.0">
<title>深圳嵌入式2023</title>
</head>
<body>
<h1>深圳嵌入式培训</h1>
</body>
</html>
4.10 Start the server
deng@local:~$ sudo ~/boa/bin/boa
deng@local:~/boa/boa$ ps -a | grep "boa"
1962 tty1 00:00:00 gsd-clipboard
1969 tty1 00:00:00 gsd-keyboard
2563 tty2 00:00:00 gsd-clipboard
2570 tty2 00:00:00 gsd-keyboard
4490 pts/1 00:00:00 boa
deng@local:~/boa/boa$
4.11 Testing
05. FAQ Discussion
Problem 1 : lex and yacc commands not found
deng@local:~/tools/boa-0.94.13/src$ make -j4
yacc -d boa_grammar.y
lex boa_lexer.l
gcc -g -O2 -pipe -Wall -I. -c -o alias.o alias.c
gcc -g -O2 -pipe -Wall -I. -c -o boa.o boa.c
make: lex: Command not found
make: yacc: Command not found
Makefile:59: recipe for target 'y.tab.c' failed
make: *** [y.tab.c] Error 127
make: *** 正在等待未完成的任务....
Makefile:62: recipe for target 'lex.yy.c' failed
make: *** [lex.yy.c] Error 127
deng@local:~/tools/boa-0.94.13/src$
Solution
sudo apt install bison
sudo apt install flex
问题2:error: pasting “t” and “->” does not give a valid preprocessing token
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
^~~
gcc -g -O2 -pipe -Wall -I. -c -o sublog.o sublog.c
<内置>: recipe for target 'util.o' failed
make: *** [util.o] Error 1
make: *** 正在等待未完成的任务....
Solution:
//问题描述:在 compat.h 文件中的宏定义问题: ‘TIMEZONE_OFFSET’
deng@local:~/tools/boa-0.94.13/src$ vim compat.h +120
找到
#define TIMEZONE_OFFSET(foo) foo##->tm_gmtoff
修改成
#define TIMEZONE_OFFSET(foo) (foo)->tm_gmtoff
119 #ifdef HAVE_TM_GMTOFF
120 //#define TIMEZONE_OFFSET(foo) foo##->tm_gmtoff
121 #define TIMEZONE_OFFSET(foo) (foo)->tm_gmtoff
122 #else
123 #define TIMEZONE_OFFSET(foo) timezone
124 #endif
deng@local:~/tools/boa-0.94.13/src$ vim boa.c +225
//注释掉226-228行
这三行注释掉,否则 boa 启动时会出现“boa.c:226 - icky linux kernel bug!: No suchfile or directory 错误”
222 /* test for failed-but-return-was-successful setuid
223 * http://www.securityportal.com/list-archive/bugtraq/2000/Jun/0101.html
224 */
225 #if 0
226 if (setuid(0) != -1) {
227 DIE("icky Linux kernel bug!");
228 }
229 #endif
问题3:log.c:73 - unable to dup2 the error log: Bad file descriptor
deng@local:~/boa/boa$ ./boa
[17/May/2023:01:08:57 +0000] log.c:73 - unable to dup2 the error log: Bad file descriptor
deng@local:~/boa/boa$
deng@local:~/boa/boa$
Solution:
deng@local:~/tools/boa-0.94.13$ vim src/log.c +73
注释掉
if (dup2(error_log, STDERR_FILENO) == -1) {
DIE("unable to dup2 the error log");
}
为:
71 #if 0
72 /* redirect stderr to error_log */
73 if (dup2(error_log, STDERR_FILENO) == -1) {
74 DIE("unable to dup2 the error log");
75 }
问题4:unable to bind: Permission denied
deng@local:~/boa/boa$ ./boa
[17/May/2023:01:14:58 +0000] boa.c:194 - unable to bind: Permission denied
Solution:
deng@local:~/boa/boa$ sudo ./boa
Problem 5 : Displayed as garbled characters
Solution:
Modify the browser encoding to utf-8
06. Appendix
Baidu Encyclopedia: boa server
Reference: boa server
Reference: [Practical] Internet of Things Security Monitoring Project [2]——Transplantation of boa server