Chinaunix首页 | 论坛 | 博客
  • 博客访问: 168205
  • 博文数量: 109
  • 博客积分: 0
  • 博客等级: 民兵
  • 技术积分: 147
  • 用 户 组: 普通用户
  • 注册时间: 2015-01-23 16:12
文章分类

全部博文(109)

文章存档

2015年(109)

我的朋友

分类: LINUX

2015-02-10 16:45:38

boa的移植


在/home目录下建立BOA文件夹
[root@localhost home]# mkdir boa


下载官方源码到BOA文件夹,并解压,得到boa-0.94.13
[root@localhost boa]# tar -zxvf boa-0.94.13.tar.gz


进入./boa-0.94.13/src,
[root@localhost boa]# cd boa-0.94.13/src


运行./configure,得到Makefile
[root@localhost src]# ./configure


修改Makefile:(一定要改为2.95.3,不然会编译不过去)
将CC = gcc 改为CC = /usr/local/arm/2.95.3/bin/arm-linux-gcc
将CPP= gcc -E 改为:CPP = /usr/local/arm/2.95.3/bin/arm-linux-gcc -E


保存后,退出


[root@localhost src]# gedit boa.c
将此句注释掉,如下:


 /* if (setuid(0) != -1) {
            DIE("icky Linux kernel bug!");
        }*/
[root@localhost src]# make


文件瘦身(可选)
[root@localhost src]# /usr/local/arm/2.95.3/bin/arm-linux-strip boa


arm-linux-readelf -d boa,察看共享库(可以略过不做)


 



将boa拷贝到网络文件系统的/bin
[root@localhost src]#cp boa /nfs/bin



将boa.conf拷贝到nfs/etc/boa/下,在此,附件提供一个修改好的boa.conf


 


 



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


# 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 0
#Group nogroup
Group 0


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


#ServerAdmin 


# 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
# 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
# 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 jimmy


# 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:  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


# 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


# 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


# DefaultType: MIME type used if the file extension is unknown, or there
# is no file extension.


DefaultType text/html


# 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 


# 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/ /var/www/cgi-bin/
ScriptAlias /index.html /var/www/index.html


 


 


 


 



创建日志文件所在目录/nfs/var/log/boa
创建HTML文档的主目录/nfs/var/www



**静态测试:
将网页放置在/nfs/var/www/目录下:
笔者在此处放置的是index.html文档(默认文件名,文档内容可以修改)


开发板加电,正常启动后,进入/bin,再输入boa,如下:



然后在地址栏里输入:
就会出现《如何看待金融危机》这篇文章。



**CGI编程:
1、编写HelloCGI.c程序
[root@localhost boa-0.94.13]# gedit helloCGI.c
(主程序的程序开头一定要用Tab,而不是空格,不然编译可能不通过)
内容如下:
#include
#include
int main(void)
{
        printf("Content-type: text/html\n\n");
        printf("\n");
        printf("CGI Output\n");
        printf("\n");
        printf("

Hello,world.

\n");
        printf("\n");
        printf("\n");
        exit(0);
}
 
2.交叉编译生成CGI程序 
[root@localhost boa-0.94.13]# /usr/local/arm/2.95.3/bin/arm-linux-gcc -o


helloCGI helloCGI.c 
在boa-0.94.13下便生成了一个可执行文件:helloCGI


将helloCGI 拷贝至根文件系统:nfs/var/www/cgi-bin/下
[root@localhost boa-0.94.13]# cp helloCGI /nfs/var/www/cgi-bin/
 
3.测试
浏览器输入:
网页出现 Hello,world. 调试成功!



 


 


 


如果打开CGI出现502错误,尝试重新编译BOA,在cgi.c文件的int complete_env


(request * req)函数最后(返回之前)添加 my_add_cgi_env(req,


"LD_LIBRARY_PATH", "/lib");


另外,如果添加了这一句话还是有问题,请检查一下你的CGI程序写得是否规范。


 


 


移植中出现的错误及解决方法


问题及解决:
Q:使用 make编译出现错误
util.c:100:1: pasting “t” and “->” does not give a valid


preprocessing token
make: *** [util.o] Error 1
A:修改 src/compat.h,找到
#define TIMEZONE_OFFSET(foo) foo##->tm_gmtoff
修改成
#define TIMEZONE_OFFSET(foo) (foo)->tm_gmtoff


Q:执行 boa 出现 “gethostbyname::No such file or directory”
A:需要将 boa.conf 里的 ServerName 开头注释去掉


Q:无法启动 Boa,error log 显示 “boa.c:266.icky Linux kernel bug!:No


such file” A:修改 src/boa.c,将下面判断语句注释:


/*if (setuid(0) != -1) {
DIE(”icky Linux kernel bug!”);


}*/
重新编译


Q:无法启动Boa,error log 显示 “boa.c:211 - getpwuid….略”


A:修改 src/boa.c,将下面判断语句注释:


/*if (passwdbuf == NULL) {
DIE(”getpwuid”);


}
if (initgroups(passwdbuf->pw_name, passwdbuf->pw_gid) == -1) {
DIE(”initgroups”);


}*/
重新编译。


 


 1.必须要在板子的/etc下建一个boa目录(错误代码忘了)


       2.”can't open boa.conf for reading“
解决:不仅要在你自己放置boa的目录下放入boa.conf配置文件,而且要在板子


的/etc/boa下也要放入boa.conf文件,这样系统在运行boa的时候才可以读取到


boa.conf文件。


       3.“unable to dup2 the error log bad file descriptor”
解决:在boa源码里,即src文件夹下把log.c中的第73行的if语句注释掉。


       4."unable to dup2 the error log:Bad file descriptor"
解决:在boa.conf里,把“#AccessLog /var/log/boa/access_log”注释掉(即去


掉#号)。


       5.“[01/Jan/2031:00:12:25 +0000] boa.c:226 - icky Linux kernel


bug!: No such file or directory”
解决:在boa源码里,即src文件夹下把boa.c中的第226行的if语句注释掉。


       6."gethostbyname:: Resource temporarily unavailable"
解决:把“#ServerName ”的“#”号去掉。


       7."./boa: 1: syntax error: "(" unexpected"
解决:没有修改Makefile,是用gcc编译的,应该改成是arm-linux-gcc编译。


       8.如果页面上是:“502 Bad Gateway The CGI was not CGI/1.1


compliant.“
解决:给你要执行的cgi可执行程序赋个权限。chmod 777 filename


       9.在

中,cgi可执行程


序的路径就直接写“cgi-bin/test2.cgi”就可以了,不要写板子上的绝对路径,这


样就重复了,因为cgi执行时会自动去boa.conf的指定的路径里找。


       10.出现警告:“control reaches end of non-void function”,是因为


某个函数没有return,而函数定义时是非void型的。所以需要有个返回值。比如int


cgiMain()这个函数就一定要有个返回值的,否则会报这个错误。


       12.运行网页时老出现错误:“mkstemp:No such file or diectory”
解决:不能用post,只能用get。因为post方式需要新建一个临时文件,这就需要用


到mkstemp函数。这个函数是在系统中以唯一的文件名创建一个文件并打开,且只有


当前用户才能访问这个临时文件。故权限不够,或其他什么问题都会报这个错误。


那么就用get吧!这里具体原因细节笔者暂时也不是很清楚...


       13.直接写的含有system()函数的c程序用arm-linux-gcc编译到板子上的可


以执行,而如果写在cgi中的就不一定能执行了。因为牵涉到一个cgi的权限的问题


。即使给你的cgi-bin文件夹下的所有cgi可执行文件都赋了权限,也不一定能执行



       解决办法就是看看你的boa.conf中的权限设置的如何。这里正确的应该是把


“User nobody Group nogroup”改为“User root  Group 0”,否则不能正确执行


!你会发现你的cgi可执行程序的其他代码都执行了,却只有这个system()函数没有


执行!


阅读(901) | 评论(0) | 转发(0) |
给主人留下些什么吧!~~