mini2440 httpd使用(busybox自带)

httpd使用(busybox自带)

by HYH | 2018 年 1 月 20 日 下午 4:17

一.说明

1.该功能需要busybox自带httpd。busybox自带的httpd的参数如下:

2.httpd可配置文件帮助(见源码:networking/httpd.c):

* httpd.conf has the following format:
*
* H:/serverroot # define the server root. It will override -h
* A:172.20. # Allow address from 172.20.0.0/16
* A:10.0.0.0/25 # Allow any address from 10.0.0.0-10.0.0.127
* A:10.0.0.0/255.255.255.128 # Allow any address that previous set
* A:127.0.0.1 # Allow local loopback connections
* D:* # Deny from other IP connections
* E404:/path/e404.html # /path/e404.html is the 404 (not found) error page
* I:index.html # Show index.html when a directory is requested
*
* P:/url:[http://]hostname[:port]/new/path
* # When /urlXXXXXX is requested, reverse proxy
* # it to http://hostname[:port]/new/pathXXXXXX
*
* /cgi-bin:foo:bar # Require user foo, pwd bar on urls starting with /cgi-bin/
* /adm:admin:setup # Require user admin, pwd setup on urls starting with /adm/
* /adm:toor:PaSsWd # or user toor, pwd PaSsWd on urls starting with /adm/
* /adm:root:* # or user root, pwd from /etc/passwd on urls starting with /adm/
* /wiki:*:* # or any user from /etc/passwd with according pwd on urls starting with /wiki/
* .au:audio/basic # additional mime type for audio.au files
* *.php:/path/php # run xxx.php through an interpreter
*
* A/D may be as a/d or allow/deny – only first char matters.
* Deny/Allow IP logic:
* – Default is to allow all (Allow all (A:*) is a no-op).
* – Deny rules take precedence over allow rules.
* – “Deny all” rule (D:*) is applied last.
*
* Example:
* 1. Allow only specified addresses
* A:172.20 # Allow any address that begins with 172.20.
* A:10.10. # Allow any address that begins with 10.10.
* A:127.0.0.1 # Allow local loopback connections
* D:* # Deny from other IP connections
*
* 2. Only deny specified addresses
* D:1.2.3. # deny from 1.2.3.0 – 1.2.3.255
* D:2.3.4. # deny from 2.3.4.0 – 2.3.4.255
* A:* # (optional line added for clarity)
*
* If a sub directory contains config file, it is parsed and merged with
* any existing settings as if it was appended to the original configuration.
*
* subdir paths are relative to the containing subdir and thus cannot
* affect the parent rules.
*
* Note that since the sub dir is parsed in the forked thread servicing the
* subdir http request, any merge is discarded when the process exits. As a
* result, the subdir settings only have a lifetime of a single request.
*
* Custom error pages can contain an absolute path or be relative to
* ‘home_httpd’. Error pages are to be static files (no CGI or script). Error
* page can only be defined in the root configuration file and are not taken
* into account in local (directories) config files.
*
* If -c is not set, an attempt will be made to open the default
* root configuration file. If -c is set and the file is not found, the
* server exits with an error.

3.mini2440本身自带了一个httpd演示程序boa。

使用busybox的httpd的时候如果不使用80端口以外的端口,需要先把它杀掉。

killall boa

二.使用

1.直接使用很简单

busybox httpd -h 网页主目录

但这样有个不足之处,就是不能使用cgi程序,打开cgi程序时不会在服务器上运行,直接下载cgi程序本身。

2.使用cgi程序

php也可以算作一种cgi程序(不过也可以直接作为http服务器的一个模块),实际处理是服务器会把*.php文件交给php运行,再读取程序返回的结果发送给客户端浏览器。因此,对于可以直接在服务器上运行的Shell脚本程序,直接交给/bin/sh运行即可。

mini2440自带的led.cgi:

#!/bin/sh

type=0
period=1

case $QUERY_STRING in
*ping*)
type=0
;;
*counter*)
type=1
;;
*stop*)
type=2
;;
esac

case $QUERY_STRING in
*slow*)
period=0.25
;;
*normal*)
period=0.125
;;
*fast*)
period=0.0625
;;
esac

/bin/echo $type $period > /tmp/led-control

echo “Content-type: text/html; charset=gb2312”
echo
/bin/cat led-result.template

exit 0

配置的httpd.conf:

*.cgi:/bin/sh

最终效果:

为了能够运行更多种类的cgi程序,需要专门编写一个程序用于启动cgi程序:

C代码:

#include <stdio.h>
#include <stdlib.h>
#include <unistd.h>
int main(int argc,char *argv[ ])
{

execv(argv[1],&argv[1]);

}

程序的原理很简单,直接使用exec函数族替换当前进程(如果产生了子进程,运行cgi程序时会提示重定向错误)。

 

https://hyhsystem.cn/wordpress/


转载于:https://www.cnblogs.com/HEYAHONG/p/8379209.html

  • 0
    点赞
  • 2
    收藏
    觉得还不错? 一键收藏
  • 0
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值