2010年3月7日 星期日

thttpd Web Server

thttpd Web Server

This is a open source light weight web server to implement HTTP/1.1, easy to setup with minimum effort to get it running.

Download a copy of thttpd to unzip.

Configure and compile it.

./configure --host=arm-linux
make



Note, if there is a conflicting getline error in extras/htpasswd.c change all the getline function to some other name eg. getlines to make it unique.

Copy the thttpd executable file to /rootfs/usr/sbin (this is assume the root filesystem is created in /rootfs directory).


cp thttpd /rootfs/usr/sbin


Create a thttpd.config file in the /rootfs/etc directory for its configuration settings.


dir=/www
user=root
cgipat=/cgi-bin/*
logfile=/tmp/thttpd.log
pidfile=/var/thttpd.pid


Add the command line to the rcS script to start up the http server.

# start HTTP server
thttpd -C /etc/thttpd.config


Create a directory for the web page.


mkdir -p /rootfs/www/cgi-bin


Create a simple index.html program in the www directory.


<html>
<head>
<title>Welcome html</title>
</head>
<body>
<h1>Hello World!</h1>
</body>
</html>


Restart the board, go to the host computer web browser and enter the url of the device ip address eg. http://192.168.114.190/index.html

Note, the board must be configured with network address over the NFS service.



However, to make our target board as a client we have to configure our host as a router which allow network traffic to be redirected to access the internet gateway, this set up assume the target and host is connected via a hub with NFS service.

First create a virtual network interface, this interface is use as a bridge to our target as a logical subnet.

ifconfig eth0:1 192.168.114.254 netmask 255.255.255.0 up

then, configure the interface routing and enable IP Forward function below.

iptables --table nat --append POSTROUTING --out-interface eth0 -j MASQUERADE
iptables --append FORWARD --in-interface eth0 -j ACCEPT
echo "1">/proc/sys/net/ipv4/ip_forward


next, in the target bootloader environment, change serverip and gateway reference to eth0:1 IP address (eg. as above 192.168.114.254) and update the bootargs.

That's it, reboot target and it should be able to access to the internet.

沒有留言:

張貼留言