码迷,mamicode.com
首页 > Web开发 > 详细

mini2440 httpd使用(busybox自带)

时间:2018-01-29 21:25:58      阅读:252      评论:0      收藏:0      [点我收藏+]

标签:使用   counter   xxxx   not found   amp   rdp   blank   time   mini2440   

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/


mini2440 httpd使用(busybox自带)

标签:使用   counter   xxxx   not found   amp   rdp   blank   time   mini2440   

原文地址:https://www.cnblogs.com/HEYAHONG/p/8379209.html

(0)
(0)
   
举报
评论 一句话评论(0
登录后才能评论!
© 2014 mamicode.com 版权所有  联系我们:gaon5@hotmail.com
迷上了代码!