mini2440 httpd Use (busybox)

Source: Internet
Author: User

httpd use (BusyBox comes with)

by Hyh | January 20, 2018 4:17

I. Description

1. This function requires BusyBox with httpd. The parameters of the httpd busybox are as follows:

2.HTTPD Configurable file Help (see Source: NETWORKING/HTTPD.C):

* Httpd.conf has the following format:
*
* H:/serverroot # define the server root. It'll override-h
* a:172.20. # Allow address from 172.20.0.0/16
* A:10.0.0.0/25 # Allow to address from 10.0.0.0-10.0.0.127
* a:10.0.0.0/255.255.255.128 # Allow to address that previous set
* a:127.0.0.1 # Allow local loopback connections
* d:* # Deny from the 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[:p Ort]/new/path
* # WHEN/URLXXXXXX is requested, reverse proxy
* # it to http://hostname[:p ort]/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 is as a/D or Allow/deny–only first char matters.
* Deny/allow IP logic:
*–default is to allow all (a:* is A no-op).
*–deny rules take precedence over allow rules.
*– "Deny all" rule (d:*) was applied last.
*
* Example:
* 1. Allow only specified addresses
* a:172.20 # Allow to any address this begins with 172.20.
* a:10.10. # Allow to any address this begins with 10.10.
* a:127.0.0.1 # Allow local loopback connections
* d:* # Deny from the 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 is appended to the original configuration.
*
* SubDir paths is relative to the containing subdir and thus cannot
* Affect the parent rules.
*
* Note that since the sub dir was parsed in the forked thread servicing the
* SubDir HTTP request, any merge are discarded when the process exits. As a
* result, the SubDir settings only has a lifetime of a single request.
*
* Custom error pages can contain an absolute path or being relative to
* ' home_httpd '. Error pages is to be static files (no CGI or script). Error
* page can only is defined in the root configuration file and is not taken
* into account in local (Directories) config files.
*
* If-c is isn't set, an attempt'll be made to open the default
* Root configuration file. If-c is set and the file are not found, the
* Server exits with an error.

3.MINI2440 itself comes with a httpd demo program Boa.

When using BusyBox's httpd, if you don't use a port other than port 80, you need to kill it first.

Killall boa

Two. Use

1. Direct use is simple

BusyBox httpd-h Page Home Directory

However, there is a disadvantage, is that you can not use the CGI program, open the CGI program will not run on the server, directly download the CGI program itself.

2. Using CGI programs

PHP can also be counted as a CGI program (but can also be directly as a module of HTTP server), the actual processing is that the server will send the *.php file to PHP to run, and then read the results returned by the program sent to the client browser. Therefore, for shell scripts that can be run directly on the server, simply hand over to the/bin/sh to run.

Mini2440 comes with the 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

Configuration of the httpd.conf:

*.cgi:/bin/sh

Final effect:

To be able to run more kinds of CGI programs, you need to write a program specifically to start the CGI program:

C Code:

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

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

}

The principle of the program is very simple, directly using the EXEC function family to replace the current process (if a child process is generated, the CGI program will be prompted to redirect the error).

https://hyhsystem.cn/wordpress/

Copyright 2018 He Yahong's blog unless otherwise noted.

mini2440 httpd Use (busybox)

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.