本测试在ubuntu1304下测试,具体步骤如下:

1下载源码:www.boa.org,可在ubuntu下自带的火狐浏览器下载,也可在window下下载,然后再移到ubuntu下;

2打开终端,将boa解压到某目录并进入当前源码目录

tar xvzf boa-*

cd /boa-0.94.13/src

3配置 ./configure

4编译

make

出现:yacc -d boa_grammar.y

make: yacc: Command not found

make: *** [y.tab.c] Error 127

分析:yacc是一个文法分析器的生成器,bison即是yacc的GNU版本.Lex和YACC是用于构造词法分析机和语法解释器的工具,利用Lex和

YACC你可以轻松的构造一个语法解释器。

解决:apt-get install bison

再make

出现:lex boa_lexer.l

     make: lex: Command not found

make: *** [lex.yy.c] Error 127

解决:apt-get install flex

再make

出现:util.c:100:1: error: pasting "t" and "->" does not give a valid preprocessing token

make: *** [util.o] Error 1

解决: 修改 src/compat.h

找到 #define TIMEZONE_OFFSET(foo) foo##->tm_gmtoff

修改成 #define TIMEZONE_OFFSET(foo) (foo)->tm_gmtoff

再make,编译通过,在当前目录生成一boa可执行程序

5 复制boa.conf到/etc/boa目录下,如果没有这个目录,自己手动创建 : sudo mkdir /etc/boa

因为在defines.h文件中,

当然也可修改此设置,在此选择默认。

6 执行./boa

出现: log.c:73 unable to dup2 the error log: Bad file descriptor

解决:注释掉:

if(dup2(error_log, STDERR_FILENO) == -1)

{   

  DIE("unable to dup2 the error log");

}

执行make,

再次执行./boa

出现:Cannot open /var/log/boa/access_log for logging: logfile

open: No such file or directory,

或者:Cannot open/var/log/boa/error_log for logging: logfile

open: No such file or directory

解决:

哪个出现,你就在boa.conf里把它给注释掉(不要忘了/etc/boa/目录下的boa.conf)

即改成:

#AccessLog /var/log/boa/access_log

再次执行./boa

此时boa服务器就已经启动!

测试1:

将index.html文件存放在/var/www/下(如果没有,则创建)

打开浏览器,输入ubuntu下的IP地址,则显示如下结果:

实例代码1:

index.html

 <html>
<head><title>boa web test page</title></head>
<body bgcolor=#666666>
<p><hr/></p>
<p><center>my boa main page</center></p)
<p><hr/></p>
<p>Boa is a tiny web server that also offers extremely high performance.
It is specifically designed to run on UNIX-like systems, which includes Linux, as well as the *BSD systems. To get all the legal stuff out of the way, Boa is available for free and is covered by the GNU Public License (GPL).The source code for Boa, as well as documentation, can be found at http://www.boa.org/.</p>
<p><hr/></p> </body>
</html>

测试2:

将自己制作的网页(hello.html)放到/var/www/目录中,将cgi程序放到/var/www/cgi-bin目录下,在浏览器中输入http://192.168.182.153/hello.html,这里的IP地址就是Linux的IP地址。则出现如下结果:

实例代码2:

hello.html

 <html>
<head>
<title>this is my first HTML page</title>
</head> <body>
<center><p><h1>this is is a simple test of <I>HTML</I></h1></p></center>
<center><img src=../../"img/logo.jpg" alt="CST studio" />
hello from <a href=../../"http://www.latelee.org"><b>Late Lee</b></a></center> <br /> <center><p>you can visit my website at <a href = "http://www.latelee.org">www.latelee.org</a></p><center>
<hr /> <!-- a test -->
<form name="form1" action="/cgi-bin/hello.cgi" method="post">
<table align="center">
<tr><td align="center" colspan="2"></td></tr>
<tr>
<td align="center">user name</td>
<td><input type="text" name="Username"></td>
</tr> <tr>
<td align="center">password</td>
<td><input type="password" name="Password"></td>
</tr> <tr>
<td><input type="submit" value="login"></td>
<td><input type="reset" value="cancel"></td>
</tr>
</table>
</form>
</body> </html>

hello.c

 #include <stdlib.h>
#include <stdio.h>
#include <string.h> char* get_cgi_data(FILE* fp, char* method)
{
char* input;
int len;
int size=;
int i=; if (strcmp(method, "GET") == ) /**< GET method */
{
input = getenv("QUERY_STRING");
return input;
} else if (strcmp(method, "POST") == ) /**< POST method */
{
len = atoi(getenv("CONTENT_LENGTH"));
input = (char*)malloc(sizeof(char) * (size+)); if (len == )
{
input[] = ' ';
return input;
} while ()
{
input[i] = (char)fgetc(fp);
if (i == size)
{
input[i+] = ' ';
return input;
}
--len; if (feof(fp) || (!(len)))
{
i++;
input[i] = ' ';
return input;
}
i++;
}
}
return NULL;
} int main(void)
{
char* input;
char* method;
char name[];
char passwd[];
int i=;
int j=; printf("Content-type:text/htmlnn");
printf("The following is query result:");
method = getenv("REQUEST_METHOD");
input = get_cgi_data(stdin, method); printf("string is: %s", input);
int len = strlen(input);
/* sizeof("username=") = 9 */
for (i=; i<len; i++)
{
if (input[i] == '&')
{
name[j]=' ';
break;
} name[j++]=input[i];
} /* sizeof("username=")+sizeof(&password=) = 19 */
for (i=+strlen(name),j=; i<(int)strlen(input); i++)
{
passwd[j++] = input[i];
}
passwd[j]=' '; printf("your username is %s your password is %sn", name, passwd); return ;
}

参考文献:

1 在ubuntu上运行boa的方法

2 Linux下小型WEB服务器boa的使用

ubuntu1304下安装boa服务器的更多相关文章

  1. Linux下安装Tomcat服务器和部署Web应用

    一.上传Tomcat服务器

  2. 转】Linux下安装Tomcat服务器和部署Web应用

    原博文出自于: http://www.cnblogs.com/xdp-gacl/p/4097608.html 感谢! 一.上传Tomcat服务器

  3. 如何在Windows下安装Tomcat服务器

    Tomcat 服务器是一个免费的开放源代码的Web 应用服务器,属于轻量级应用服务器,在中小型系统和并发访问用户不是很多的场合下被普遍使用,是开发和调试JSP 程序的首选服务器.在Windows下安装 ...

  4. JavaWeb入门——在Linux环境下安装Tomcat服务器

    JavaWeb入门——在Linux环境下安装Tomcat服务器 摘要:本文主要学习了如何在Linux环境下安装Tomcat服务器. 准备工作 检查Java环境变量 检查系统是否配置了Java的环境变量 ...

  5. JavaWeb入门——在Windows环境下安装Tomcat服务器

    JavaWeb入门——在Windows环境下安装Tomcat服务器 摘要:本文主要学习如何在Windows环境中下载并安装Tomcat服务器. 下载 获取安装包 推荐去官网上下载Tomcat: htt ...

  6. Linux 下安装 Tomcat 服务器和部署 Web 应用

    一.上传Tomcat服务器 二.安装Tomcat服务器 2.1.解压tomcat服务器压缩包 2.2.配置环境变量 tomcat服务器运行时是需要JDK支持的,所以必须配置好JDK用到的那些环境变量 ...

  7. Linux下安装Tomcat服务器

    Linux下安装Tomcat服务器 一.总结 一句话总结: linux多用才能熟 1.阿里云上面我们买的服务器,怎么让它可以访问特定的端口? 就是给服务器的安全组添加规则:实例-->更多--&g ...

  8. 如何在linux下安装tomcat服务器

    linux作为现在比较主流的服务器操作系统,使用的机器广泛,安全稳定.tomcat作为应用容器当然可以有linux版本的tomcat.在linux上安装tomcat的方式也很简单,只需要运行脚本基本配 ...

  9. 转 Linux下安装Tomcat服务器和部署Web应用

    转载声明: http://www.cnblogs.com/xdp-gacl/p/4097608.html 一.上传Tomcat服务器

随机推荐

  1. Entity Framework实体框架使用TrackerEnabledDbContext进行操作日志跟踪

    在EF实体框架中进行日志跟踪,一般都是自己写个Log实体类,在数据保存时进行属性原始值验证来进行日志跟踪.当然还可以使用一些第三扩展库例如:entity framework extended进行日志记 ...

  2. 安装DirectX SDK时出现Error Code:s1023 的解决方案

    刚刚安装DXSDK_Jun10时(下载地址:http://download.microsoft.com/download/A/E/7/AE743F1F-632B-4809-87A9-AA1BB3458 ...

  3. UrlPathEncode与UrlEncode的区别

    UrlEncode与UrlPathEncode 的基本作用都是对 URL 字符串进行编码 不同点总结如下: 不同点 UrlEncode UrlPathEncode 处理空格的方式 替换成“+” 替换成 ...

  4. Android(java)学习笔记76:多线程-定时器概述和使用

    定时器: 定时器是一个应用十分广泛的线程工具,可用于调度多个定时任务以后台线程的方式执行. 在Java中,可以通过Timer和TimerTask类来实现定义调度的功能 Timer public Tim ...

  5. struts2 后台action向前端JSP传递参数的问题

    后台有个方法,里面部分代码如下: System.out.print("alter:"+user.getId()); User temp=userservice.getUserByU ...

  6. fatal error LNK1123: 转换到 COFF 期间失败: 文件无效或损坏

    为完成老师的任务,用c++写个计算器,又去学点c++,结果就有各种问题,如题 http://www.cnblogs.com/newpanderking/articles/3372969.html 感谢 ...

  7. CSS之导航菜单

    <!DOCTYPE html> <html lang="en"> <head> <meta charset="UTF-8&quo ...

  8. eclipse 必备

    eclipse编辑器太小  http://jingyan.baidu.com/article/fc07f98974f40c12fee51959.html 新建jsp文件报错     http://ji ...

  9. MVC5----用户登陆及验证码

    随便写写记录一下学习的过程 登陆 Models中添加添加 public class LoginViewModel { [Required(ErrorMessage = "*")] ...

  10. Swift中的注释以及表达式

    Swift程序有两类注释:单行注释(//)和多行注释(/*...*/).注释方法与C.C++和Objective-C语言都是类似的,下面详细介绍一下.1. 单行注释单行注释可以注释整行或者一行中的一部 ...