转自:http://hi.baidu.com/arise_xue/blog/item/e40612fb99a47b294e4aead8.html 一,安装: 1,下载 http://www.boa.org/ 2,解压 # tar xzf boa-0.94.13.tar.gz 3,编译 # cd boa-0.94.13/src # ./configure 生成了makefile文件, 修改makefile文件, 把其中的 CC CPP 改为: CC = arm-linux-gcc CPP = arm-linux-g++ 4,然后make # make (在这一步用3.4.1和3.3.2交叉编译器时均出现如下错误: util.c: 100: 1: pasting “t” and “->” does not give a valid preprocessing token make: [util.o] Error1 换成2.95.3交叉编译器后,编译通过。 另一种解决办法是把compat.h中的 foo##->tm_gmtoff的##去掉。) 删除调试信息(可以不做,目的是减小文件大小): 5,# arm-linux-strip boa 二,配置: 1,Boa需要在/etc目录下建立一个boa目录,里面放置Boa的主要配置文件boa.conf,Boa源码下已经有一个示例boa.conf,可以在其基础上修改,主要改动如下: Group nogroup 修改为 Group 0 ScriptAlias /cgi-bin/ /usr/lib/cgi-bin/ 修改为 ScriptAlias /cgi-bin/ /var/www/cgi-bin/ #ServerName www.your.org.here 去掉这一行的注释符"#",网址可任意。如不去掉这行的注释,会出现如下错误: gethostbyname:: Resource temporarily unavailable错误。 2,创建日志文件所在目录/var/log/boa,创建HTML文档的主目录/var/www,将静态网页存入该目录下(可将主机/usr/share/doc/HTML/目录下的index.html文件和img目录复制到/var/www目录下)。 创建CGI脚本所在目录/var/www/cgi-bin,将cgi的脚本存放在该目录下。 另外还要将mime.types文件复制到/etc目录下,通常可以从Linux主机的/etc目录下直接复制即可。 3,将Boa可执行文件复制到根文件系统/usr/bin目录下,烧写根文件系统。 4,注意:在运行Boa前要把/var/log/boa挂载上ramfs文件系统,使其可写,否则出现如下错误: log.c:73 – Unable to dup2 the error log: Bad file r. 在板子上方放的cgi程序,html文件,一定要把权限修改对,修改成 755 在实验箱上运行Boa(如果执行时候有错误: # ./boa [27/Nov/1990:13:22:25 + 0000]boa.c:266.icky Linux kernel bug!:No such fileBae 将 User 0修改成 User nobodyBae ) 在主机IE上输入http://arm的ip 或http://arm的ip/cig-bin/helloworld.cgi 可看到网页 三,一个简单的cgi测试程序: 1,html文件: ------------------------------------- <html> <head> <title>CGI Testing</title> </head> <body> <table width="200" height="180" border="0" style="font-size:12px"> <tr><td> <div style="font-weight:bold; font-size:15px">Method: GET</div> <div>lease input two number:<div> <form method="get" action="./cgi-bin/get"> <input type="txt" size="3" name="a">+ <input type="txt" size="3" name="b">= <input type="submit" value="sum"> </form> </td></tr> <tr><td> <div style="font-weight:bold; font-size:15px">Method: POST</div> <div>lease input two number:<div> <form method="post" action="./cgi-bin/post"> <input type="txt" size="3" name="m">* <input type="txt" size="3" name="n">= <input type="submit" value="resu"> </form> </td></tr> <tr><td><inputtype="button" value="Back Home"onclick='javascript:window.location="./index.html"'></td></tr> </table> </body> </html> ------------------------------ 2,get.c : ------------------------------ #include <stdio.h> #include <stdlib.h> int main(void) { char *data; char a[10],b[10]; printf("Content-Type:text/html\n\n"); printf("<HTML>\n"); printf("<HEAD>\n<TITLE >Get Method</TITLE>\n</HEAD>\n"); printf("<BODY>\n"); printf("<div style=\"font-size:12px\">\n"); data = getenv("QUERY_STRING"); if(sscanf(data,"a=%[^&]&b=%s",a,b)!=2) { printf("<DIV STYLE=\"COLOR:RED\">Errorarameters should be entered!</DIV>\n"); } else { printf("<DIV STYLE=\"COLOR:GREEN; font-size:15px;font-weight:bold\">a + b = %d</DIV>\n",atoi(a)+atoi(b)); } printf("<HR COLOR=\"blue\" align=\"left\" width=\"100\">"); printf("<input type=\"button\" value=\"Back CGI\" onclick=\"javascript:window.location='../cgi.html'\">"); printf("</div>\n"); printf("</BODY>\n"); printf("</HTML>\n"); return 0; } ------------------------------ 3,post.c: ------------------------------ #include <stdio.h> #include <stdlib.h> int main(void) { int len; char *lenstr,poststr[20]; char m[10],n[10]; printf("Content-Type:text/html\n\n"); printf("<HTML>\n"); printf("<HEAD>\n<TITLE >ost Method</TITLE>\n</HEAD>\n"); printf("<BODY>\n"); printf("<div style=\"font-size:12px\">\n"); lenstr=getenv("CONTENT_LENGTH"); if(lenstr == NULL) { printf("<DIV STYLE=\"COLOR:RED\">Errorarameters should be entered!</DIV>\n"); } else { len=atoi(lenstr); fgets(poststr,len+1,stdin); if(sscanf(poststr,"m=%[^&]&n=%s",m,n)!=2) { printf("<DIV STYLE=\"COLOR:RED\">Error: Parameters are not right!</DIV>\n"); } else { printf("<DIV STYLE=\"COLOR:GREEN; font-size:15px;font-weight:bold\">m * n = %d</DIV>\n",atoi(m)*atoi(n)); } } printf("<HR COLOR=\"blue\" align=\"left\" width=\"100\">"); printf("<input type=\"button\" value=\"Back CGI\" onclick=\"javascript:window.location='../cgi.html'\">"); printf("</div>\n"); printf("</BODY>\n"); printf("</HTML>\n"); fflush(stdout); return 0; } ------------------------------ 4, 把两个c程序编译完成,复制到开发搬上, 通过其它pc访问测试html页面,调用这两个cgi, 其中如果出现: 502 Bad Gateway The CGI was not CGI/1.1 compliant. 错误, 有可能是如下原因: (1)将.cgi文件拷贝至目标板上后,必须改变其权限 chmod 755 * (2)测试程序中“//“的问题。参考<Web服务器--Boa实验笔记> http://www.pc51.net/system/unix/linux/2007-02-07/6888.html (3)修改 BOA 源码 cgi.c 添加环境变量: my_add_cgi_env(req, "LD_LIBRARY_PATH", "/lib");(函数complete_env中)再重新交叉编译即可 (4) 同时请修改下 boa对CGI支持的缺陷。 (5)出现这个问题的原因是关于“库”方面的原因。如果你编译CGI文件的时候,用静态编译,则编译的时候,会自动地加入库。 arm-linux-gcc -static test.c -o test.cgi (http://topic.csdn.net/t/20061120/13/5171006.html#有相关讨论) (6) 说它不支持http 1.1 协议,那你在ie中也使用http 1.0协议访问它试试看。方法是点“工具”->"internet选项“->"高级",把“使用http 1.1协议"前面的勾去掉。 (7)如果是用flashfxp工具传送文件到目标板上,请选用二进制模式传送。我自己就出错在这里,在此感谢网友newzy帮忙解决这个问题。 (8)对程序进行静态编译,然后再放到板子上, 我在测试中遇到的是 权限问题,在测试中,试图向一个文件中写入一条日志,总是出现 502这个错误, 修改了这个文件的权限到 755 后,可正常运行 5,如果需要以root权限执行boa, 需要修改boa.c中 if (setuid(0) != -1) { DIE("icky Linux kernel bug!"); 去掉这句, 把 boa.conf 中的user 该为 root RedHat9¸0+linux上配置和使用BOA服务器文档信息(pdf) http://www.docin.com/p-6920114.html |