Linux下使用的輕量級WEB服務器主要有:lighttpd、thttpd、shttpd和boa等等,而Boa是使用最爲普遍的輕量級WEB服務器之一(固然,阿帕奇是世界使用排名第一的Web服務器軟件)。Boa是一種很是小巧的Web服務器,其可執行代碼只有大約60KB左右。做爲一種單任務Web服務器,Boa只能依次完成用戶的請求,而不會fork出新的進程來處理併發鏈接請求。但Boa支持CGI,可以爲CGI程序fork出一個進程來執行,Boa的設計目標是速度和安全。html
工具鏈爲:arm-hismall-linux-gcc,海思平臺。linux
1、Boa移植web
1.下載boa-0.94.13.tar.gz瀏覽器
http://download.csdn.net/detail/huangminqiang201209/5769107安全
2.編譯服務器
[root@localhostweb]#tar xzvf boa-0.94.13.tar.gz併發
[root@localhostweb]#cd boa-0.94.13工具
[root@localhostboa-0.94.13]#cd src/測試
[root@localhostsrc]#./configure //生成Makefileui
[root@localhostsrc]#vi Makefile
30:CC = gcc
31:CPP = gcc -E
該爲:
CC= arm-hismall-linux-gcc
CPP= arm-hismall-linux-gcc -E
[root@localhostsrc]# vi compat.h
120:#define TIMEZONE_OFFSET(foo) foo##->tm_gmtoff //##的做用是把2個參數合併到一塊兒
修改爲
#defineTIMEZONE_OFFSET(foo) (foo)->tm_gmtoff
[root@localhostsrc]# vi log.c
72:if (dup2(error_log, STDERR_FILENO) == -1) {
DIE("unable to dup2 the errorlog");
}
爲(即屏蔽):
/*if (dup2(error_log, STDERR_FILENO) == -1){
DIE("unable to dup2 the errorlog");
}*/
[root@localhostsrc]#vi boa.c
73:if (dup2(error_log, STDERR_FILENO) == -1) {
DIE("unable to dup2 the errorlog");
}
爲(即屏蔽):
/*if (dup2(error_log, STDERR_FILENO) == -1){
DIE("unable to dup2 the errorlog");
}*/
211:if (passwdbuf == NULL) {
DIE(」getpwuid」);
}
if (initgroups(passwdbuf->pw_name,passwdbuf->pw_gid) == -1) {
DIE(」initgroups」);
}
爲(即屏蔽):
#if 0
if (passwdbuf == NULL) {
DIE(」getpwuid」);
}
if (initgroups(passwdbuf->pw_name,passwdbuf->pw_gid) == -1) {
DIE(」initgroups」);
}
#endif
[root@localhostsrc]# make
[root@localhostsrc]#arm-hismall-linux-strip boa //去除調試信息,減少體積。(可選)
2、配置Boa
1)boa.conf
Boa須要在/etc目錄下創建一個boa目錄,裏面放入Boa的主要配置文件boa.conf。在boa-0.94.13目錄下已有一個示例boa.conf,能夠在其基礎上進行修改。
[root@localhost src]# cd ..
[root@localhost boa-0.94.13]# vi boa.conf
(1)Group的修改
修改Group nogroup爲Group 0 //開發板上有的組,設爲0
(2)user的修改
修改User nobody爲User 0
(3)Alias的修改
修改ScriptAlias /cgi-bin/ /usr/lib/cgi-bin/ 爲 Alias /cgi-bin/ /www/cgi-bin/
(4)DoucmentRoot的修改
修改DoucmentRoot /var/www 爲DoucmentRoot /www
(5)ServerName的設置
修改#ServerName www.your.org.here爲 ServerName www.your.org.here,不然會出現錯誤「gethostbyname::No such file or directory」
(6)AccessLog修改
修改AccessLog/var/log/boa/access_log爲#AccessLog /var/log/boa/access_log,不然會出現錯誤提示:「unable to dup2 the errorlog: Bad file deor」
2)開發板etc配置
/etc $mount-t nfs -o nolock 192.168.1.211:/work/nfs /nfs
/etc $cp/nfs/mime.types .
/etc $mkdir boa
/etc $cd/boa
/etc/boa $ cp /nfs/web/boa-0.94.13/boa.conf.
/etc/boa $cp/nfs/web/boa-0.94.13/src/boa .
/etc/boa $mkdir /www
/etc/boa $ mkdir -p/www/cgi-bin
3)運行boa
/etc/boa $./boa
[16/Jul/2013:19:22:51+0000] boa: server version Boa/0.94.13
[16/Jul/2013:19:22:51+0000] boa: server built Jul 17 2013 at 10:38:13.
[16/Jul/2013:19:22:51+0000] boa: starting server pid=718, port 80
3、Boa測試
1)靜態網頁測試
將靜態網頁存入根文件系統的/www目錄下(/1.jpg即爲/www/1.jpg)
/www $ cat index.html
<html>
<body>
<h1>My First Heading </h1>
<p>This is a paragraph</p>
<h2>My First Heading </h2>
<a href="http://www.baidu.com">This is a link</a>
<img src="/1.jpg" width="104" height="142" />
</body>
</html>
直接在瀏覽器中輸入開發板的IP地址(好比個人是http://192.168.1.66) ,出現以下畫面。靜態HTML調試成功。
2)CGI功能測試
1)生成GCI可執行程序
[root@localhost for_test]# cat helloworldCGI.c
#include<stdio.h>
#include<stdlib.h>
int main(void)
{
printf("Content-type: text/html\n\n");
printf("<html>\n");
printf("<head><title>CGI Output</title></head>\n");
printf("<body>\n");
printf("<h1>Hello,world.</h1>\n");
printf("<body>\n");
printf("</html>\n");
exit(0);
}
[root@localhost for_test]# chmod 777 helloworldCGI.c
[root@localhost for_test]# arm-hismall-linux-gcc helloworldCGI.c
2)開發板端
/etc/boa$cp /nfs/for_test/a.out /www/cgi-bin/
3)瀏覽器
在瀏覽器輸入: http://192.168.1.66/cgi-bin/a.out ,網頁出現 Hello,world. 調試成功!
4、參考文獻
boa web服務器移植 :http://blog.chinaunix.net/uid-25544300-id-3227511.html
三種嵌入式web服務器(Boa / lighttpd / shttpd)的 linux移植筆記 :http://blog.chinaunix.net/uid-26921272-id-3322975.html