Detailed explanation of embedded web boa configuration process

Preliminary preparation

boa introduction

Boa server is a small and efficient web server. It is a single-task http server that runs under unix or linux, supports CGI, and is suitable for embedded systems. It has open source code and high performance. Boa 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.

Operational purpose

The purpose of this process is to deploy and configure boa server on Feiling development board, the platform is aarch64, verify the success of the process through a simple logical login page, and report errors in the process.

Download boa

boa official website address:www.boa.org
Remember not to select 0.94.14rc21. There is no configure file in the src directory after decompression. Select 0.94.13 is available for download here. The download format is boa-0.94.13.tar.gz
Please add image description

Configuration process

First connect the target IP and transfer boa's compressed package. For example: If you are using Ubuntu, use xftp or MobaXterm or FileZilla Client to transfer boa-0.94.13.tar.gz to Ubuntu.

(The history will be appended to the end of this article, temporarily appendix A)

1. Unzip boa server

We assume that you have entered the Ubuntu home path and started to decompress boa
sudo tar zxvf boa-0.94.13.tar.gz
cd boa-0.94.13
sudo apt-get install bison flex
cd src
./configure Generate Makefile

2.Configure Makefile

What needs to be noted here is that if your target is the X86 platform, you can skip step 2. If your target platform is aarch64 arm, etc., you need to modify the makefile.

查看平台架构:uname -m
文件显示行号:按键Esc,输入英文:set nu 或者:set number

Makefile changes CC CPP in two points, as shown in the figure.
Execute
sudo vi Makefile
Please add image description
Dear friends, please note that aarch64-linux-gnu-gcc is tab-completed. Don't knock yourself silly.

3. Compile boa server

It is currently in the src directory, that is, the current path (in my case) is /home/graysen/boa-0.94.13/src

3.1 Edit defines.h
sudo vi defines.h
Please add image description
This is the root directory of the web server, which is the storage location of web and cgi.

3.2 Edit boa.c

sudo vi boa.c
Please add image description
3.3 Edit compat.h

sudo vi compat.h

Please add image description
3.4 Edit log.c

sudo vi log.c

Please add image description
It should be noted here that the function of commenting log.c is to determine whether to display the printout of starting the boa server. For example, if I comment, the detailed execution status will be displayed in the shell when boa is started; if not, there will be no output after starting boa. (Results will be displayed in the /boa/log directory regardless of whether they are commented or not)

The editing and modification of the file has been completed
It is currently in the src directory

执行
sudo make

Start compiling


After compilation is completed, start installing boa server
In the src directory
sudo mkdir -p /boa /boa/www /boa/cgi- bin /boa/log
Please add image description
cd …
Return to the boa-0.94.13 directory and copy the compiled file to the boa server location
Execute
sudo cp boa.conf /boa
sudo cp src/boa /boa
sudo cp src/boa_indexer /boa
sudo cp /etc/mime.types /boa

Please add image description

4. Modify boa configuration file

We placed the boa server in the root directory
cd /boa
sudo vim boa.conf

Please add image description
Please add image description
#ErrorLog /var/log/boa/error_log is the error log that is directed to be output here. If you do not want to log errors, please set it to /dev/null.
Please add image description
Please add image description
DocumentRoot /boa/www is the directory of your web, where the web is stored.
Please add image description
Please add image description
Please add image description
ScriptAlias ​​/cgi-bin/ /boa/cgi-bin/ is where it is stored. c.cgi file, of course you can specify any place. You can create cgi-bin under www for storage, then you need to modify it here:
ScriptAlias ​​/cgi-bin/ /boa/www /cgi-bin/
Please add image description
For the specific meaning of the fields, please refer to the official website for explanationhttp://www.boa.org/documentation/boa-2.html# ss2.3

(This article will put the full text of boa.conf at the end, and remember Appendix B for now)

5. Increase permissions and compile cgi

Modify boa permissions

cd /boa
sudo chmod 777 *

Write a simple html demo and store it under /boa/www

<html>
<head>
<title>CGI login</title>
<meta http-equiv="Content-Type" content="text/html; charset=utf-8">
</head> 
<body>  
<form name="login" action="../cgi-bin/login.cgi">name:<input type="text" name="name" />
<br/>password:<input type="password" name="pwd" /> 
<br/>true:<input type="submit" value="login" />
</form>
</body>
</html>

Write a simple c demo and store it in /boa/cgi-bin after compilation.

#include<stdio.h> 
#include<stdlib.h>   
int main() 
{
    
       
    char *date;   
    char name[50],pwd[20];   
    printf("content-type:text/html;charset=utf-8\n\n");  
    printf("<TITLE>login ret</TITLE>");
    printf("<H3>login ret</h3>");    
    date=getenv("QUERY_STRING");  
    if(date==NULL)    
        printf("<p>err</p>");  
    else
    {
    
        
        sscanf(date,"name=%[^&]&pwd=%s",name,pwd);  
        printf("<p>name=%s</p>",name);   
        printf("<p>pwd=%s</p>",pwd);   
        printf("%s",date);  
    }   
    return 0; 
}
printf("content-type:text/html;charset=utf-8\n\n");  如果你自己C文件这句话一定要加上

注意:
If you are running on the X86 platform, please use gcc to compile
If you are running on the aarch64 arm platform, please use aarch64-linux-gnu-gcc or arm-linux-gnueabi-gcc Compile

Take me as an example, use aarch64-linux-gnu-gcc to compile

Please add image description
Store my sample code login.cgi in /boa/cgi-bin

sudo cp login.cgi /boa/cgi-bin
and increase permissions
(currently I have switched to the /boa/cgi-bin directory Next)
sudo chmod 777 *(or sudo chmod 777 login.cgi)

6. Test demo

You will see boa in the /boa directory
Execute
./boa
Start the server

Open the browser and enter (your ubuntu ip or development board ip) (the port set by boa.conf)
Take me as an example: 192.168.31.201:8080
Please add image description
The page is displayed successfully and the account password is entered

Please add image description
Successfully jumps to /cgi-bin/login.cgi and displays correctly

7.Error examples

7.1 -bash: ./boa: cannot execute binary file: Exec format error
-bash: ./boa: cannot execute binary file: Exec format error may be caused by There is a problem with your cross-compilation. It is possible that your target environment is aarch64, but you compiled the C file with gcc. Please try to modify the makefile, use the correct compiler to compile, and follow the makefile-compile C-target environment to be consistent.

7.2Could not chdir to “/etc/boa”: aborting
The definition of this directory is in defines.h. Maybe your boa server directory is not configured or the configuration path is wrong. , according to our example, #define SERVER_ROOT is modified to "/boa"

7.3 502 Bad GatewayThe CGI was not CGI/1.1 compliant

出现
502 Bad Gateway
The CGI was not CGI/1.1 compliant
cgi_header: unable to find LFLF

The reasons are as follows:
1. The URL may be wrong (whether the path corresponds to the configuration file)
2. There is a configuration problem
3. Insufficient permissions are given to chmod 777 test.cgi
4. There is a problem with the code itself (test cgi-test.cgi first)< a i=5> 5. The c code uses the wrong compiler to generate cgi 6. Try turning off the firewalls at both ends, turning off tinder, etc.

Please add image description

If it still doesn't work after checking that everything is correct, you can try to reconfigure and transplant boa.

7.4 GET http://192.168.77.149:888/favicon.ico

GET http://192.168.77.149:888/favicon.ico appears during network debugging and capture
Please add image description

It shows that you do not have a favicon.ico file, just pass in the favicon.ico file under /boa/www

favicon.ico is generally used as an abbreviated website logo. It is displayed in the address bar of the browser, on the browser tab or on the favorites. It is an abbreviated logo that shows the personality of the website.

You can use the online conversion page to convert any image to favicon.ico


Appendix Ahistory

cd boa-0.94.13/
ls
sudo apt-get install bison flex
cd src/
sudo ./configure 
ls
sudo vi defines.h 
sudo vi boa.c
sudo vi compat.h 
sudo make
sudo mkdir -p /boa /boa/www /boa/cgi-bin /boa/log
sudo cp boa.conf /boa
sudo cp src/boa /boa
sudo cp src/boa_indexer /boa
sudo cp /etc/mime.types /boa
sudo cp test.html /boa/www/
sudo cp test.c /boa/cgi-bin/
sudo ufw disable

Appendix B boa.conf

# Boa v0.94 configuration file
# File format has not changed from 0.93
# File format has changed little from 0.92
# version changes are noted in the comments
#
# The Boa configuration file is parsed with a lex/yacc or flex/bison
# generated parser.  If it reports an error, the line number will be
# provided; it should be easy to spot.  The syntax of each of these
# rules is very simple, and they can occur in any order.  Where possible
# these directives mimic those of NCSA httpd 1.3; I saw no reason to 
# introduce gratuitous differences.

# $Id: boa.conf,v 1.25 2002/03/22 04:33:09 jnelson Exp $

# The "ServerRoot" is not in this configuration file.  It can be compiled
# into the server (see defines.h) or specified on the command line with
# the -c option, for example:
#
# boa -c /usr/local/boa


# 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
Port 8080

# Listen: the Internet address to bind(2) to.  If you leave it out,
# it takes the behavior before 0.93.17.2, which is to bind to all
# addresses (INADDR_ANY).  You only get one "Listen" directive,
# if you want service on multiple IP addresses, you have three choices:
#    1. Run boa without a "Listen" directive
#       a. All addresses are treated the same; makes sense if the addresses
#          are localhost, ppp, and eth0.
#       b. Use the VirtualHost directive below to point requests to different
#          files.  Should be good for a very large number of addresses (web
#          hosting clients).
#    2. Run one copy of boa per IP address, each has its own configuration
#       with a "Listen" directive.  No big deal up to a few tens of addresses.
#       Nice separation between clients.
# The name you provide gets run through inet_aton(3), so you have to use dotted
# quad notation.  This configuration is too important to trust some DNS.

#Listen 192.68.0.5

#  User: The name or UID the server should run as.
# Group: The group name or GID the server should run as.

User nobody
#Group nogroup
Group nobody

# ServerAdmin: The email address where server problems should be sent.
# Note: this is not currently used, except as an environment variable
# for CGIs.

#ServerAdmin root@localhost

# ErrorLog: The location of the error log file. If this does not start
# with /, it is considered relative to the server root.
# Set to /dev/null if you don't want errors logged.
# If unset, defaults to /dev/stderr

#ErrorLog /var/log/boa/error_log
ErrorLog /boa/log/error_log
# Please NOTE: Sending the logs to a pipe ('|'), as shown below,
#  is somewhat experimental and might fail under heavy load.
# "Usual libc implementations of printf will stall the whole
#  process if the receiving end of a pipe stops reading."
#ErrorLog "|/usr/sbin/cronolog --symlink=/var/log/boa/error_log /var/log/boa/error-%Y%m%d.log"

# AccessLog: The location of the access log file. If this does not
# start with /, it is considered relative to the server root.
# Comment out or set to /dev/null (less effective) to disable 
# Access logging.

#AccessLog /var/log/boa/access_log
AccessLog /boa/log/access_log
# Please NOTE: Sending the logs to a pipe ('|'), as shown below,
#  is somewhat experimental and might fail under heavy load.
# "Usual libc implementations of printf will stall the whole
#  process if the receiving end of a pipe stops reading."
#AccessLog  "|/usr/sbin/cronolog --symlink=/var/log/boa/access_log /var/log/boa/access-%Y%m%d.log"

# UseLocaltime: Logical switch.  Uncomment to use localtime 
# instead of UTC time
#UseLocaltime

# VerboseCGILogs: this is just a logical switch.
#  It simply notes the start and stop times of cgis in the error log
# Comment out to disable.

#VerboseCGILogs

# ServerName: the name of this server that should be sent back to 
# clients if different than that returned by gethostname + gethostbyname 

#ServerName www.your.org.here

# VirtualHost: a logical switch.
# Comment out to disable.
# Given DocumentRoot /var/www, requests on interface 'A' or IP 'IP-A'
# become /var/www/IP-A.
# Example: http://localhost/ becomes /var/www/127.0.0.1
#
# Not used until version 0.93.17.2.  This "feature" also breaks commonlog
# output rules, it prepends the interface number to each access_log line.
# You are expected to fix that problem with a postprocessing script.

#VirtualHost 

# DocumentRoot: The root directory of the HTML documents.
# Comment out to disable server non user files.

#DocumentRoot /var/www
DocumentRoot /boa/www
# UserDir: The name of the directory which is appended onto a user's home
# directory if a ~user request is recieved.

UserDir public_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

# DirectoryMaker: Name of program used to create a directory listing.
# Comment out to disable directory listings.  If both this and
# DirectoryIndex are commented out, accessing a directory will give
# an error (though accessing files in the directory are still ok).

#DirectoryMaker /usr/lib/boa/boa_indexer
DirectoryMaker /boa/boa_indexer
# DirectoryCache: If DirectoryIndex doesn't exist, and DirectoryMaker
# has been commented out, the the on-the-fly indexing of Boa can be used
# to generate indexes of directories. Be warned that the output is 
# extremely minimal and can cause delays when slow disks are used.
# Note: The DirectoryCache must be writable by the same user/group that 
# Boa runs as.

# DirectoryCache /var/spool/boa/dircache

# KeepAliveMax: Number of KeepAlive requests to allow per connection
# Comment out, or set to 0 to disable keepalive processing

KeepAliveMax 1000

# KeepAliveTimeout: seconds to wait before keepalive connection times out

KeepAliveTimeout 10

# MimeTypes: This is the file that is used to generate mime type pairs
# and Content-Type fields for boa.
# Set to /dev/null if you do not want to load a mime types file.
# Do *not* comment out (better use AddType!)

#MimeTypes /etc/mime.types
MimeTypes /boa/mime.types
# DefaultType: MIME type used if the file extension is unknown, or there
# is no file extension.

DefaultType text/plain

# CGIPath: The value of the $PATH environment variable given to CGI progs.

CGIPath /bin:/usr/bin:/usr/local/bin

# SinglePostLimit: The maximum allowable number of bytes in 
# a single POST.  Default is normally 1MB.

# AddType: adds types without editing mime.types
# Example: AddType type extension [extension ...]

# Uncomment the next line if you want .cgi files to execute from anywhere
#AddType application/x-httpd-cgi cgi

# Redirect, Alias, and ScriptAlias all have the same semantics -- they
# match the beginning of a request and take appropriate action.  Use
# Redirect for other servers, Alias for the same server, and ScriptAlias
# to enable directories for script execution.

# Redirect allows you to tell clients about documents which used to exist in
# your server's namespace, but do not anymore. This allows you to tell the
# clients where to look for the relocated document.
# Example: Redirect /bar http://elsewhere/feh/bar

# Aliases: Aliases one path to another.
# Example: Alias /path1/bar /path2/foo

Alias /doc /usr/doc

# ScriptAlias: Maps a virtual path to a directory for serving scripts
# Example: ScriptAlias /htbin/ /www/htbin/

#ScriptAlias /cgi-bin/ /usr/lib/cgi-bin/
ScriptAlias /cgi-bin/ /boa/cgi-bin/

Guess you like

Origin blog.csdn.net/qq_44333320/article/details/134195283