尧图网站设计 尧图网站设计YAOTU DESIGN
ARTICLE DETAIL

资讯详情

深耕网站设计与一线实操的经验洞察。

ubuntu下boa服务器编译运行

ubuntu下boa服务器编译运行 一.下载boa源码并解压官网网站BOA源码点击箭头所指的位置即可下载解压tar -xvf boa-0.94.13.tar.gz解压完成得到目录二.安装环境所缺依赖否则编译会报错sudo apt install bison sudo apt install flex三.编译1.生成Makefile/boa-0.94.13/src$ ./configure2.在src,执行makeandand-VirtualBox:~/linux网络编程/boa/boa-0.94.13/src$ make bison -y -d boa_grammar.y gcc -g -O2 -pipe -Wall -I. -c -o y.tab.o y.tab.c y.tab.c: In function ‘yyparse’: y.tab.c:1191:16: warning: implicit declaration of function ‘yylex’ [-Wimplicit-function-declaration] yychar yylex ();会编译报错解决在src/compat.h文件120行#define TIMEZONE_OFFSET(foo) foo##-tm_gmtoff 改为#define TIMEZONE_OFFSET(foo) foo-tm_gmtoff编译完成会在src下面生成可执行文件boa运行boa,出现报错解决创建/etc/boa目录 关于该目录的定义在 defines.h中。继续运行又报错解决拷贝boa-0.94.13/boa.conf文件到/etc/boa目录下。继续运行又报错注释掉在src/log.c 72-74行if (dup2(error_log, STDERR_FILENO) -1) { DIE(unable to dup2 the error log); }又一个报错解决AccessLog /var/log/boa/access_log 改为 #AccessLog /var/log/boa/access_log发现改了也不行后面把boa.conf cp到了etc/boa/下面进行了替换就OK了修改url路劲当前编译环境OK需要修改boa.conf文件因为我们输入url的时候会在对应的路劲下面去找如果路劲不对就会找不到页面出现404在我的虚拟机下面我放了如下文件在boa.conf做如下修改111行DocumentRoot /home/and/www最后一行ScriptAlias /cgi-bin/ /home/and/www/cgi-bin/其中/cgi-bin/指的就是当我们访问的文件带有cgi-bin字段的时候就表示动态网页信息因此我们的服务器就会从后面的路劲/home/and/www/cgi-bin/下面去寻找此文件。注意这里的路劲使用绝对路径否则出现找不到的情况。还有/cgi-bin/最后面的/一定不能缺少不然还是找不到。四.运行效果看一下进程运行情况ps -a | grep boa在index.htmlhtml head titletable/title meta charsetUTF-8 /head body 选择你的车型 select optionBMW/option option玛莎拉蒂/option option火车/option option selected宝骏/option option自行车/option /select /body /html效果如下在pass.html输入如下html head meta http-equivContent-Type contenttext/html; charsetutf-8 / title用户登陆验证/title /head body form nameform1 action/cgi-bin/pass.cgi methodPOST table aligncenter trtd aligncenter colspan2/td/tr tr td alignright用户名/td tdinput typetext nameUsername/td /tr tr td alignright密 码/td tdinput typepassword namePassword/td /tr tr tdinput typesubmit value登 录/td tdinput typereset value取 消/td /tr /table /form /body /html在pass.c输入如下/* cgi例子 */ //pass.c #include stdio.h #include stdlib.h #include string.h char* getcgidata(FILE* fp, char* requestmethod); int main(void) { char *input; char *req_method; char name[64]; char pass[64]; int i 0; int j 0; // printf(Content-type: text/plain; charsetiso-8859-1\n\n); printf(Content-type: text/html\n\n); printf(The following is query reuslt:brbr); req_method getenv(REQUEST_METHOD); input getcgidata(stdin, req_method); // 我们获取的input字符串可能像如下的形式 // UsernameadminPasswordaaaaa // 其中Username和Password都是固定的 // 而admin和aaaaa都是变化的也是我们要获取的 // 前面9个字符是UserName // 在UserName和之间的是我们要取出来的用户名 for ( i 9; i (int)strlen(input); i ) { if ( input[i] ) { name[j] \0; break; } name[j] input[i]; } // 前面9个字符 Password10个字符 Username的字符数 // 是我们不要的故省略掉不拷贝 for ( i 19 strlen(name), j 0; i (int)strlen(input); i ) { pass[j] input[i]; } pass[j] \0; printf(Your Username is %sbrYour Password is %sbr \n, name, pass); return 0; } char* getcgidata(FILE* fp, char* requestmethod) { char* input; int len; int size 1024; int i 0; if (!strcmp(requestmethod, GET)) { input getenv(QUERY_STRING); return input; } else if (!strcmp(requestmethod, POST)) { len atoi(getenv(CONTENT_LENGTH)); input (char*)malloc(sizeof(char)*(size 1)); if (len 0) { input[0] \0; return input; } while(1) { input[i] (char)fgetc(fp); if (i size) { input[i1] \0; return input; } --len; if (feof(fp) || (!(len))) { i; input[i] \0; return input; } i; } } return NULL; }编译为pass.cgi编译 gcc pass.c -o pass.cgi 并赋予权限一般我都是直接拉满 chnod 777 pass.cgi运行效果
返回列表