Monday, June 25, 2007

Web Server (lighttpd) on OpenWrt

Web Server Installation & Configuration
lighttpd (dep. libpcre, libpthread, libsqlite3, libxml2, zlib)
ipkg install http://downloads.openwrt.org/backports/rc6/lighttpd_1.4.11-1_mipsel.ipk
lighttpd.conf

Edit /etc/lighttpd.conf
modify server.document-root to point it to /opt/www
uncomment server.port = 81

add a file /opt/www/index.html with "It Works!"


Create a file /etc/init.d/S80lighttpd
#!/bin/sh

BINDIR=/usr/sbin/
BIN=lighttpd
DEFAULT=/etc/default/$BIN
LOG_D=/var/log/$BIN
RUN_D=/var/run
PID_F=$RUN_D/$BIN.pid
[ -f $DEFAULT ] && . $DEFAULT

case $1 in
start)
mkdir -p $LOG_D
mkdir -p $RUN_D
${BINDIR}${BIN} $OPTIONS
;;
stop)
[ -f $PID_F ] && kill $(cat $PID_F)
;;
*)
echo "usage: $0 (start|stop)"
exit 1
esac

exit $?

chmod +x /etc/init.d/S80lighttpd

For Port forwarding from port 80 to 81 (Running Web server on port 81 for external website along with the configuration Web UI on port 80)
  • iptables-mod-nat (dep. kmod-ipt-net)

insert the following lines in /etc/firewall.user
iptables -t nat -A prerouting_wan -p tcp --dport 80 -j REDIRECT --to-port 81
iptables -A input_wan -p tcp --dport 81 -j ACCEPT

Start the lighttpd service and test it.

No comments: