• ubuntu1304下安装boa服务器


    本测试在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

     1 <html>
     2 <head><title>boa web test page</title></head>
     3 <body bgcolor=#666666>
     4 <p><hr/></p>
     5 <p><center>my boa main page</center></p)
     6 <p><hr/></p>
     7 <p>Boa is a tiny web server that also offers extremely high performance.
     8  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>
     9 <p><hr/></p>
    10 
    11 </body>
    12 </html>
    View Code

    测试2:

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

    实例代码2:

    hello.html

     1 <html>
     2 <head>
     3 <title>this is my first HTML page</title>
     4 </head>
     5 
     6 <body>
     7 <center><p><h1>this is  is a simple test of <I>HTML</I></h1></p></center>
     8 <center><img src=../../"img/logo.jpg" alt="CST studio" />
     9 hello from <a href=../../"http://www.latelee.org"><b>Late Lee</b></a></center>
    10  
    11 <br />
    12 
    13 <center><p>you can visit my website at <a href = "http://www.latelee.org">www.latelee.org</a></p><center>
    14 <hr />
    15 
    16 <!-- a test -->
    17   <form name="form1" action="/cgi-bin/hello.cgi" method="post">
    18    <table align="center">
    19       <tr><td align="center" colspan="2"></td></tr>
    20       <tr>
    21       <td align="center">user name</td>
    22       <td><input type="text" name="Username"></td>
    23       </tr>
    24 
    25       <tr>
    26         <td align="center">password</td>
    27         <td><input type="password" name="Password"></td>
    28       </tr>
    29       
    30       <tr>
    31         <td><input type="submit" value="login"></td>
    32         <td><input type="reset" value="cancel"></td>
    33       </tr>
    34     </table>
    35   </form>
    36 </body>
    37 
    38 </html>
    View Code

    hello.c

     1 #include <stdlib.h>
     2 #include <stdio.h>
     3 #include <string.h>
     4 
     5 char* get_cgi_data(FILE* fp, char* method)
     6 {
     7     char* input;
     8     int len;
     9     int size=1024;
    10     int i=0;
    11 
    12     if (strcmp(method, "GET") == 0)  /**< GET method */
    13     {
    14         input = getenv("QUERY_STRING");
    15         return input;
    16     }
    17 
    18     else if (strcmp(method, "POST") == 0)  /**< POST method */
    19     {
    20         len = atoi(getenv("CONTENT_LENGTH"));
    21         input = (char*)malloc(sizeof(char) * (size+1));
    22 
    23         if (len == 0)
    24         {
    25             input[0] = ' ';
    26             return input;
    27         }
    28 
    29         while (1)
    30         {
    31             input[i] = (char)fgetc(fp);
    32             if (i == size)
    33             {
    34                 input[i+1] = ' ';
    35                 return input;
    36             }
    37             --len;
    38 
    39             if (feof(fp) || (!(len)))
    40             {
    41                 i++;
    42                 input[i] = ' ';
    43                 return input;
    44             }
    45             i++;
    46         }
    47     }
    48     return NULL;
    49 }
    50 
    51 int main(void)
    52 {
    53     char* input;
    54     char* method;
    55     char name[64];
    56     char passwd[64];
    57     int i=0;
    58     int j=0;
    59 
    60     printf("Content-type:text/htmlnn");
    61     printf("The following is query result:");
    62     method = getenv("REQUEST_METHOD");
    63     input = get_cgi_data(stdin, method);
    64 
    65     printf("string is: %s", input);
    66     int len = strlen(input);
    67      /* sizeof("username=") = 9 */
    68     for (i=9; i<len; i++)
    69     {        
    70         if (input[i] == '&')
    71         {
    72             name[j]=' ';
    73             break;
    74         }
    75         
    76         name[j++]=input[i];
    77     }
    78 
    79      /* sizeof("username=")+sizeof(&password=) = 19 */
    80     for (i=19+strlen(name),j=0; i<(int)strlen(input); i++)
    81     {
    82         passwd[j++] = input[i];
    83     }
    84     passwd[j]=' ';
    85 
    86     printf("your username is %s your password is %sn", name, passwd);
    87 
    88     return 0;
    89 }
    View Code

    参考文献:

    1 在ubuntu上运行boa的方法

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

  • 相关阅读:
    【刷题-LeetCode】154 Find Minimum in Rotated Sorted Array II
    【刷题-LeetCode】153 Find Minimum in Rotated Sorted Array
    【刷题-LeetCode】152 Maximum Product Subarray
    迭代器,生成器
    python 16 装饰器
    python 15 闭包函数
    python 14 名称空间与作用域
    函数参数
    python 11 函数基础
    python中list、tuple、set、dict区别
  • 原文地址:https://www.cnblogs.com/gjianw217/p/3333788.html
Copyright © 2020-2023  润新知