cgi/html Web-surfing "turn" on embedded Linux via Boa server

Source: Internet
Author: User
Tags small web server

Transferred from: http://blog.csdn.net/tianmohust/article/details/6595996

Copyright NOTICE: This article for Bo Master original article, without Bo Master permission not reproduced.

Introduction to cgi/html Web surfing on embedded Linux via Boa server:
The first step is to transplant the BOA program
1. Download Boa Source
2. Generate Makefile File
3. Modify the Makefile file
4. Compiling
The second step of the BOA configuration
The third step is the implementation of BOA
1. RAMDisk the root system on the computer host Mount &nda
Introduction to cgi/html Web surfing on embedded Linux via Boa server:
The first step is to transplant the BOA program

1. Download Boa Source

2. Generate Makefile File

3. Modify the Makefile file

4. Compiling

The second step of the BOA configuration

The third step is the implementation of BOA

1. RAMDisk the root system on the host computer Mount–o loop ramdisk target directory to expand

2. Test action

3. Re-package the RAMDisk file to the embedded board

4. CGI Script test

Brief introduction

With the rise of internet technology, in the management and interaction of embedded devices, web-based applications become the mainstream, this program structure is very familiar with the B/s structure, that is, in the embedded device running a support script or CGI function of the Web server, to generate dynamic pages, It is very convenient and practical to manage and monitor embedded devices on the client side only through a Web browser. This section focuses on the development and porting of this application.

Embedded Web server porting because the embedded device resources are generally limited, and do not need to be able to handle many user requests at the same time, so do not use Linux under the most commonly used servers such as Apache, but need to use some specifically for the embedded device design of the Web server, These web servers are ideally suited for embedded applications in both storage space and runtime memory space.

Typical embedded Web servers are boa (http://www.boa.org/) and thttpd (http://www.acme.com/software/thttpd/), etc., The main difference between them and high-performance Web servers such as Apache is that they are typically single-process servers that can respond to another user's request only after a user request has been completed, but this is sufficient for embedded device applications.

Boa is a very small Web server with executable code of only about 60KB. It is a single-task Web server that can only complete the user's request sequentially, without fork out a new process to handle the concurrent connection request. But Boa supports CGI, which is able to fork out a process for CGI programs to execute. Boa's design goals are speed and safety, and Boa's performance is better than the Apache server in its site-published performance tests.

Description: The following porting and operation is performed on the at91rm9200 chip linux2.4.27.

The first step is to transplant the BOA program

This step of the work is done on the mainframe computer.

For Uclinux-dist, make Menuconfig in the Application menu, select Boa under Network application and then perform make compilation in the Uclinux-dist directory.

For the platform with MMU, such as Armlinux and Ppclinux, are to download a boa tarball on the internet, just find a mainstream version of the available, not the latest and not the oldest. Download to Redhat host, extract to any directory, and then modify the compiler inside the boa/src/makefile, just add two or three lines, the following steps:

1. Download Boa Source

: http://www.boa.org/, or http://sourceforge.net/

Latest release version: 0.94.13

Download boa-0.94.13.tar.gz, note: The Boa-0.94.13.tar.tar is downloaded from the BOA, the same as the decompression method

Unzip: # tar Xzf boa-0.94.13.tar.gz

2. Generate Makefile File

Boa-0.94.13.tar.gz after decompression, generate boa-0.94.13 directory, run directly./Computer host directory/boa-0.94.13/src/configure file

3. Modify the Makefile file

A. Modify CC = gcc

For CC =/USR/LOCAL/ARM/2.95.3/BIN/ARM-LINUX-GCC (depending on the compiler location of the host computer)

b, modify CPP = Gcc-e

For CPP =/USR/LOCAL/ARM/2.95.3/BIN/ARM-LINUX-GCC-E

Note: boa-0.94.13 compiled with the 3.3.2 and 3.4.1 compilers does not pass. There is no specific study.

4. Compiling

Enter:/Computer host Directory/BOA-0.94.13/SRC directory

# make

#/usr/local/arm/2.95.3/bin/arm-linux-strip Boa (this is to get rid of the compilation information generated in the BOA to make the file smaller)

The second step of the BOA configuration

This step of the work is also done on the computer host.

There is an example boa.conf under the BOA source boa-0.94.13 directory on the computer host, which can be modified on its basis. As follows:

1. Changes to Group

Modify Group Nogroup

For Group 0

Since there is no Nogroup group in the/etc/group file, it is set to 0. In addition, there are nobody users in/etc/passwd, so user nobody is not modified.

2. Modification of Scriptalias

Modify Scriptalias/cgi-bin//usr/lib/cgi-bin/

For scriptalias/cgi-bin//var/www/cgi-bin/

3, the ServerName setting

Modify ServerName www.linuxidc.com

For ServerName www.linuxidc.com

Note: This default is not open, and performing Boa will exit abnormally, prompting "Gethostbyname::no such file or directory", so you must open it. Other default settings.

Note: boa.conf, the following explains the meaning of the file:

#监听的端口号, the default is 80, generally without modification

Port 80

# The IP address of the bind call, which is generally commented out, indicates that all IP addresses that are bound to the server are Inaddr_any

#Listen 192.68.0.5

#作为哪个用户运行, that is, it has the user's permissions, is generally nobody, need/etc/passwd

#nobody用户

User Nobody

#作为哪个用户组运行, that is, it has the permissions of the user group, is generally nogroup, need in/etc/group

#件中有nogroup组

Group Nogroup

#当服务器发生问题时发送报警的email地址, not currently used, commented out

#ServerAdmin [email protected]

#错误日志文件. If it does not start with/, it means starting from the root path of the server. If you do not need the error log,

Then use #/dev/null. When setting up below, be sure to set up the/var/log/boa directory

Errorlog/var/log/boa/error_log

#访问日志文件. If it does not start with/, it means starting from the root path of the server. If you do not need the error log,

It is #/dev/null or commented out directly. When setting up below, be sure to set up the/var/log/boa directory

#AccessLog/var/log/boa/access_log

#是否使用本地时间. If it is not commented out, the local time is used. Use UTC when commenting out

#UseLocaltime

#是否记录CGI运行信息, if it is not commented out, the record, the comment is not recorded

#VerboseCGILogs

#服务器名字

ServerName http://www.linuxidc.com

#是否启动虚拟主机功能, that is, devices can have multiple network interfaces, each of which can have a virtual Web service

#务器. Generally commented out, i.e. no need to start

#VirtualHost

#非常重要, the home directory of the HTML document. If it does not start with/, it means starting from the root path of the server.

Documentroot/var/www

#如果收到一个用户请求的话, add a directory name after the user's home directory

Userdir public_html

#HTML目录索引的文件名, and no user indicates only the file name that is returned when the directory is accessed

DirectoryIndex index.html

#当HTML目录没有索引文件时, the user only indicates that when the directory is accessed, Boa calls the program to generate the index file and then

#返回给用户, because the process is relatively slow, it is best not to execute, you can comment out or to each HTML directory plus #directoryindex specified file

#DirectoryMaker/usr/lib/boa/boa_indexer

#如果DirectoryIndex不存在, and Directorymaker is annotated, then use the BOA Index

#生成程序来生成目录的索引文件并输出到下面目录, the directory must be BOA capable of reading and writing

# Directorycache/var/spool/boa/dircache

#一个连接所允许的HTTP持续作用请求最大数目, comment or set to 0 will turn off HTTP persistence

Keepalivemax 1000

#HTTP持续作用中服务器在两次请求之间等待的时间数, in seconds, time-out will close the connection

KeepAliveTimeout 10

#指明mime the. types file location. If it does not start with/, it means starting from the root path of the server. Can comment out

#避免使用mime. types file, you need to use AddType in this document to specify

Mimetypes/etc/mime.types

#文件扩展名没有或未知的话, the default MIME type used

DefaultType Text/plain

#提供CGI程序的PATH环境变量值

Cgipath/bin:/usr/bin:/usr/local/bin

#将文件扩展名和MIME类型关联起来, as with the Mime.types file. If you use Mime.types

#文件, then comment out, if you do not use the Mime.types file, you must use the


#AddType application/x-httpd-cgi CGI

#指明文档重定向路径

#Redirect/bar Http://elsewhere/feh/bar

#为路径加上别名

Alias/doc/usr/doc

#非常重要, indicates the actual path corresponding to the virtual path of the CGI script. Generally all CGI scripts are placed in the actual path

#里, enter site + virtual path +cgi when user accesses execution

scriptalias/cgi-bin//var/www/cgi-bin/

The third step is the implementation of BOA

This step of the work is also done on the computer host. But the directory you are working with is related to the directory on the embedded board.

1. RAMDisk the root system on the host computer Mount–o loop ramdisk target directory to expand

Go to the root folder after you expand RAMDisk, and then do the following:

# Mkdir/var/log

# Mkdir/var/log/boa (Create log file directory)

# mkdir/var/www (Create home directory for HTML documents)

# Mkdir/etc/boa

Copy the modified boa.conf file in the second step from the directory on the host computer to the relevant directory of the Ramdsik

# CP/PC host Directory/boa-0.94.13/boa.conf/etc/boa/

Copy the Mime.types file to the/etc directory of the embedded board Ramdsik, usually mime.types can be copied directly from the Linux computer host's/etc directory.

# cp/etc/mime.type/etc/

Compile the generated Boa executable in the first step above and copy it into the Ramdsik Bin directory after expansion.

# CP/PC host Directory/boa-0.94.13/src/boa/bin/

2. Test action

Can be host/usr/share/doc/html/directory under the index.html (this is a static HTML page display file, is the RedHat9 Welcome home page, when the LAN on the PC's IE input HTTP/s Embedded Board IP address will display this default static Web page) file and img directory copied to the embedded Ramdsik/var/www directory

# cp/usr/share/doc/html/index.html/var/www/

# cp/usr/share/doc/html/img/var/www/

# cp/usr/share/doc/html/index-zh_ch.html/var/www/

3. Download the RAMDisk file to the embedded board by re-packaging compression.

RAMDisk re-package compression downloaded to the board, in the root of the super terminal of the board to enter./boa, see if Boa can execute.

Possible error such as: libso.0.6 GLIB2.2 version of the problem, this is generally the BOA implementation need to dynamically share the library, the solution is to compile the boa in a static way to compile, that is

Enter:/Computer host Directory/BOA-0.94.13/SRC directory, modify the makefile file:

Ldflags = g

Modified to: Ldflags =-static on it.

Other errors may occur when you execute boa, and you can find the reason in the/var/log/boa/error_log file on the board. Most are related to the correctness of the boa.conf configuration file. Such as:

Issue: Error occurred while executing./boa: Boa execution, error log.c:73 unable to dup2 the error Log:bad file descriptor

Workaround: Comment out the IF statement in the LOG.C.

Another problem arises: unable to dup2 the error Log:bad file descriptor

Workaround: Comment out #accesslog/var/log/boa/access_log in boa.conf

4. CGI Script test

Write the following test.c test program,

#include

#include

int main (void)

{

printf ("contenttype:text/html");

printf ("");

printf ("");

printf ("
");

printf ("

This is an HTML page generated from with in a CGI program.
");

printf ("


--------------------------------------------------------------------------------

");

printf ("Go-to-out put.html page");

printf ("");

printf ("");

Fflush (stdout);

}

Cross compilation Build test.cgi

#/usr/local/arm/2.95.3/bin/arm-linux-gcc-o test.cgi test.c

Copy the test.cgi to the/var/www/cgi-bin/of the embedded board, and enter the IP address of the embedded board on IE on the LAN PC/cgi-bin/test.cgi

You can display the test.cgi page.

Knowledge of CGI can be learned: using C language to implement CGI-related data.

Note: When the above code executes, an error message may appear:

502 Bad Gateway

The CGI is not cgi/1.1 compliant.

Possible causes:

1. Test to see if you can browse static Web pages to ensure that the network is correct.

On the top "the third step of the 2." Test operation "After the LAN on the PC's IE input http://Embedded Board IP address, if you can display RedHat9 welcome home page, indicating that static access is correct.

2. After you copy the. cgi file to the target board, you must change its permissions

chmod 755 test.cgi

Otherwise, the upper computer will be prompted with the above error when browsing

3. The most likely problem is the CGI program itself.

We have seen test.c print at the beginning with the MIME header information ″content Type:text/html″ to represent the output HTML source code to the Web server. Note that any MIME header information must have a blank line after it is added,

So this must be guaranteed.

4. The original file of TEST.c is edited in text mode and cannot be executed under Linux

Can change: Dos2unix test.c change and then compile

5. Another possibility, test.cgi is compiled into a dynamic form, however, the program executes in the embedded in the dynamic library file, so in the compilation of the program with-static, compiled into a static form, but this compiled file is very large, in the embedded is not suitable for this way.

cgi/html Web-surfing "turn" on embedded Linux via Boa server

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.