More than 1 webserver behind DD-WRT

Post new topic   Reply to topic    DD-WRT Forum Index -> Broadcom SoC based Hardware
Goto page 1, 2, 3, 4, 5, 6, 7, 8  Next
Author Message
frater
DD-WRT Guru


Joined: 07 Jun 2006
Posts: 2777

PostPosted: Sun Sep 14, 2008 7:09    Post subject: More than 1 webserver behind DD-WRT Reply with quote
I'm running several webservers behind my router and want them all to be accessed using port 80 using subdomains. I have a toplevel-domain with a wildcard which points to my IP-adress. Previously everything went to my Fedora Linux-server.
Now everything goes directly to its appropriate server based on the requested host.

Hosts defined on the DD-WRT will get automatically in the configuration.

Here are the steps to install all this (edited on 23-9-2008):

Install Optware
Install libuclibc++ (/opt/bin/ipkg-opt install libuclibc++)
Install pound (/opt/bin/ipkg-opt install pound)
make a startup script
make a script to write the config
Enter a firewall rule
Make sure everything is started

startup script
~# cat /opt/etc/init.d/S80pound
Code:
#!/bin/sh

prefix="/opt"
cfg=/tmp/pound/pound.cfg

PATH=${prefix}/bin:${prefix}/sbin:/sbin:/bin:/usr/sbin:/usr/bin
NAME=pound
DAEMON=${prefix}/sbin/${NAME}
POUND_CTL_DIR="/tmp"
POUNDCTL_BIN="${prefix}/sbin/poundctl"

test -x $DAEMON || exit 0

if [ -z "$1" ] ; then
    case `echo "$0" | sed 's:^.*/\(.*\):\1:g'` in
        S??*) rc="start" ;;
        K??*) rc="stop" ;;
        *) rc="usage" ;;
    esac
else
    rc="$1"
fi

case "$rc" in
    start)
        echo "Writing $cfg"
        /opt/sbin/write_pound_cfg
        echo "Starting $NAME"
        if [ -n "`pidof $NAME`" ]; then
            echo "$NAME already running"
        else
            if [ ! -e $cfg ]; then
              echo "missing $cfg"
              exit 1
            fi
            $DAEMON -v -f $cfg
        fi
        ;;
    stop)
        if [ -n "`pidof $NAME`" ]; then
            echo "Stopping $NAME"
            killall $NAME 2> /dev/null
        else
            echo "$NAME already stopped"
            exit 1
        fi
        ;;
    restart)
        "$0" stop
        sleep 1
        "$0" start
        ;;
    status)
        if [ -n "`pidof $NAME`" ]; then
            $POUNDCTL_BIN -c /tmp/pound.ctl
        else
            echo "$NAME is not running"
            exit 1
        fi
        ;;
    *)
        echo "Usage: $0 (start|stop|restart|usage|status)"
        ;;
esac

exit 0

chmod +x /opt/etc/init.d/S80pound


# cat /opt/sbin/write_pound_cfg
Code:
SRCDIR=/opt/etc/pound
CONFDIR=/tmp/pound
CONF=${CONFDIR}/pound.cfg
mkdir -p ${CONFDIR} 2>/dev/null

cat ${SRCDIR}/pound.pt1 >${CONF}

_write_conf ()
{
 _HOST=`echo ${HOST_NAME} | sed 's/\./\\\./g'`
 echo -e "\n\tService \"${HOST_NAME}\"" >>${CONF}
 echo -e "\t\tHeadRequire \"^Host:[\\\t ]*${_HOST}$\"" >>${CONF}
 echo -e "\t\tBackend" >>${CONF}
 echo -e "\t\t\tAddress ${HOST_IP}" >>${CONF}
 echo -e "\t\t\tPort 80\n\t\tend\n\tend" >>${CONF}
}

cat /etc/hosts | grep -v -e 0.0.0.0 -e localhost | while read HOST_ENTRY
do
  HOST_IP=`echo $HOST_ENTRY | awk '{print $1}'`
  HOST_NAME=`echo $HOST_ENTRY | awk '{print $2}'`

  _write_conf
done
cat /tmp/dnsmasq.conf | grep ^address= | grep -v in-addr.arpa | while read HOST_ENTRY
do
  HOST_IP=`echo $HOST_ENTRY | cut -d/ -f3`
  HOST_NAME=`echo $HOST_ENTRY | cut -d/ -f2`

  _write_conf
done

cat ${SRCDIR}/pound.pt2 >>${CONF}

chmod +x /opt/sbin/write_pound_cfg

# cat /opt/etc/pound/pound.pt1
Code:
TimeOut         120
Alive           30
Control         "/tmp/pound.ctl"

ListenHTTP
        Address 0.0.0.0
        Port 8080


# cat /opt/etc/pound/pound.pt2
Code:
        Service "loadbalancing"
                HeadRequire "^Host:[\t ]*bbs\.mirmana\.com$"
                BackEnd
                        Address 192.168.10.130
                        Port 80
                End
                Backend
                        Address 192.168.10.120
                        Port 80
                End
        End
        Service "ASSP"
                HeadRequire "^Host:[\t ]*assp\.mirmana\.com$"
                BackEnd
                        Address 192.168.10.130
                        Port 55555
                End
        End
        Service "2 domains"
                HeadRequire "^Host:[\t ]*(subdomain1|subdomain2)\.mirmana\.com$"
                BackEnd
                        Address 192.168.10.210
                        Port 9091


                End
        End
        Service "Default"
                BackEnd
                        Address 192.168.10.130
                        Port 80
                End
        End
End


Startup code:
Code:

/opt/etc/init.d/S80pound start


Firewall:
Code:
iptables -I INPUT 1 -p tcp --dport 8080 -j ACCEPT

_________________
Asus RT16N + OTRW
Kingston 4GB USB-disk 128 MB swap + 1.4GB ext3 on /opt + 2 GB ext3 on /mnt
Copperjet 1616 modem in ZipB-config
Asterisk, pixelserv & Pound running on router
Another Asus RT16N as WDS-bridge

DD-WRT v24-sp2 vpn (c) 2010 NewMedia-NET GmbH
Release: 12/16/10 (SVN revision: 15758M)


Last edited by frater on Tue Sep 23, 2008 15:03; edited 4 times in total
Sponsor
soulstace
DD-WRT Guru


Joined: 04 Aug 2007
Posts: 6427

PostPosted: Sun Sep 14, 2008 7:12    Post subject: Reply with quote
Looks like good wiki material. You should create an article for it. Who knows if forum post will ever be lost by purging..
frater
DD-WRT Guru


Joined: 07 Jun 2006
Posts: 2777

PostPosted: Sun Sep 14, 2008 7:26    Post subject: Reply with quote
Aha... thanks...
I wait for comments and ideas of others...

Are you installing it?

_________________
Asus RT16N + OTRW
Kingston 4GB USB-disk 128 MB swap + 1.4GB ext3 on /opt + 2 GB ext3 on /mnt
Copperjet 1616 modem in ZipB-config
Asterisk, pixelserv & Pound running on router
Another Asus RT16N as WDS-bridge

DD-WRT v24-sp2 vpn (c) 2010 NewMedia-NET GmbH
Release: 12/16/10 (SVN revision: 15758M)
victorine
DD-WRT Novice


Joined: 14 Sep 2008
Posts: 1

PostPosted: Sun Sep 14, 2008 7:50    Post subject: Reply with quote
4 entrecotes?? Shocked
frater
DD-WRT Guru


Joined: 07 Jun 2006
Posts: 2777

PostPosted: Tue Sep 23, 2008 15:04    Post subject: Reply with quote
No-one tried it yet?
I've seen several people asking for this feature....

I need testers!!!

_________________
Asus RT16N + OTRW
Kingston 4GB USB-disk 128 MB swap + 1.4GB ext3 on /opt + 2 GB ext3 on /mnt
Copperjet 1616 modem in ZipB-config
Asterisk, pixelserv & Pound running on router
Another Asus RT16N as WDS-bridge

DD-WRT v24-sp2 vpn (c) 2010 NewMedia-NET GmbH
Release: 12/16/10 (SVN revision: 15758M)
graegos
DD-WRT Novice


Joined: 08 Jul 2008
Posts: 43

PostPosted: Tue Oct 14, 2008 9:46    Post subject: My Setup Reply with quote
Here's a description of my current setup:

1 wrt54g-tm build 10328

1 Ubuntu web server with port 80 forwarded to server ip, there are a total of 3 websites hosted on this server.

I need to host one more web server appliance on the wrt54g-tm.

Ready to test this out, not sure how to begin though if anyone can help!

_________________
Router Model: Buffalo WZR-HP-AG300H
Firmware Version: Firmware: DD-WRT v3.0-r46733 std (05/21/21)
Kernel Version: Linux 3.10.108-d11 #81419 Fri May 21 12:44:07 +07 2021 mips
frater
DD-WRT Guru


Joined: 07 Jun 2006
Posts: 2777

PostPosted: Wed Oct 15, 2008 16:54    Post subject: Reply with quote
First you install Optware:

if it's not enabled, enable jffs on your router and clean it, then reboot

SSH to your router...

Code:
mkdir /jffs/opt
mount -o bind /jffs/opt /opt
wget http://www.wlan-sat.com/boleo/optware/optware-install-ddwrt.sh  -O - | tr -d '\r' > /tmp/optware-install.sh
sh /tmp/optware-install.sh

If everything has gone alright, you can continue.

Now install Pound and uclibc++

Code:
/opt/bin/ipkg-opt install libuclibc++
/opt/bin/ipkg-opt install pound


For starters, copy the attached file to /tmp and execute the following code.
Code:
tar xvf /tmp/poundcfg.tar -C /


Add the following to your startup code:
Code:
mount -o bind /jffs/opt /opt
/opt/etc/init.d/S80pound start


Add this to the firewall script
Code:
iptables -I INPUT 1 -p tcp --dport 8080 -j ACCEPT

And add a port forward from port 80 to port 8080 of the LAN-IP.
Enable DNSMasq and set your LAN domain. Also enable Local DNS.

You should then manually modify the file /opt/etc/pound/pound.pt2
It's only an example script and sort of self-explanatory ;-)

You can start the reverse proxy with the command:
Code:
/opt/etc/init.d/S80pound start


The startup script writes a config file to /tmp/pound/pound.cfg
Check if this file is written and makes sense.



sshot-46.png
 Description:
 Filesize:  14.01 KB
 Viewed:  48044 Time(s)

sshot-46.png



sshot-45.png
 Description:
 Filesize:  6.77 KB
 Viewed:  48044 Time(s)

sshot-45.png



poundcfg.tar
 Description:

Download
 Filename:  poundcfg.tar
 Filesize:  9.5 KB
 Downloaded:  2095 Time(s)


_________________
Asus RT16N + OTRW
Kingston 4GB USB-disk 128 MB swap + 1.4GB ext3 on /opt + 2 GB ext3 on /mnt
Copperjet 1616 modem in ZipB-config
Asterisk, pixelserv & Pound running on router
Another Asus RT16N as WDS-bridge

DD-WRT v24-sp2 vpn (c) 2010 NewMedia-NET GmbH
Release: 12/16/10 (SVN revision: 15758M)


Last edited by frater on Sat Nov 01, 2008 16:46; edited 1 time in total
frater
DD-WRT Guru


Joined: 07 Jun 2006
Posts: 2777

PostPosted: Thu Oct 23, 2008 16:43    Post subject: Re: My Setup Reply with quote
graegos wrote:
Here's a description of my current setup:

1 wrt54g-tm build 10328

1 Ubuntu web server with port 80 forwarded to server ip, there are a total of 3 websites hosted on this server.

I need to host one more web server appliance on the wrt54g-tm.

Ready to test this out, not sure how to begin though if anyone can help!

Are you still there...??
I took some extra effort to make it easy for you...

_________________
Asus RT16N + OTRW
Kingston 4GB USB-disk 128 MB swap + 1.4GB ext3 on /opt + 2 GB ext3 on /mnt
Copperjet 1616 modem in ZipB-config
Asterisk, pixelserv & Pound running on router
Another Asus RT16N as WDS-bridge

DD-WRT v24-sp2 vpn (c) 2010 NewMedia-NET GmbH
Release: 12/16/10 (SVN revision: 15758M)
graegos
DD-WRT Novice


Joined: 08 Jul 2008
Posts: 43

PostPosted: Sat Dec 13, 2008 8:11    Post subject: Reverse Proxy Included in Mega Build? Reply with quote
Hi Frater, this is all too complex, and I could imagine the nightmare of having to redo & re-enter everything every time I upgrade firmware for the router. I see you entered a ticket to have this implemented possibly in a mega build:

http://svn.dd-wrt.com:8000/dd-wrt/ticket/757

This would be a more reasonable implementation option and I would like to thank you for trying to get this accomplished.

_________________
Router Model: Buffalo WZR-HP-AG300H
Firmware Version: Firmware: DD-WRT v3.0-r46733 std (05/21/21)
Kernel Version: Linux 3.10.108-d11 #81419 Fri May 21 12:44:07 +07 2021 mips


Last edited by graegos on Sat Dec 13, 2008 8:33; edited 1 time in total
frater
DD-WRT Guru


Joined: 07 Jun 2006
Posts: 2777

PostPosted: Sat Dec 13, 2008 8:14    Post subject: Reply with quote
Please add a comment to TRAC stating you would like to get it too....
_________________
Asus RT16N + OTRW
Kingston 4GB USB-disk 128 MB swap + 1.4GB ext3 on /opt + 2 GB ext3 on /mnt
Copperjet 1616 modem in ZipB-config
Asterisk, pixelserv & Pound running on router
Another Asus RT16N as WDS-bridge

DD-WRT v24-sp2 vpn (c) 2010 NewMedia-NET GmbH
Release: 12/16/10 (SVN revision: 15758M)
graegos
DD-WRT Novice


Joined: 08 Jul 2008
Posts: 43

PostPosted: Mon Dec 15, 2008 22:47    Post subject: Reply with quote
Frater, I see pound has been added and you have made a few more posts in the bug trac area, when can we potentially test this reverse proxy?
_________________
Router Model: Buffalo WZR-HP-AG300H
Firmware Version: Firmware: DD-WRT v3.0-r46733 std (05/21/21)
Kernel Version: Linux 3.10.108-d11 #81419 Fri May 21 12:44:07 +07 2021 mips
frater
DD-WRT Guru


Joined: 07 Jun 2006
Posts: 2777

PostPosted: Tue Dec 16, 2008 17:39    Post subject: Reply with quote
I'm waiting for a binary that has pound included. I mailed Eko some scripts and maybe he incorporates them as well...

It's quite easy for me because I also know how it's supposed to work in concept. I think there are a lot of DD-WRT users who want this feature although they don't know it yet Laughing

_________________
Asus RT16N + OTRW
Kingston 4GB USB-disk 128 MB swap + 1.4GB ext3 on /opt + 2 GB ext3 on /mnt
Copperjet 1616 modem in ZipB-config
Asterisk, pixelserv & Pound running on router
Another Asus RT16N as WDS-bridge

DD-WRT v24-sp2 vpn (c) 2010 NewMedia-NET GmbH
Release: 12/16/10 (SVN revision: 15758M)
graegos
DD-WRT Novice


Joined: 08 Jul 2008
Posts: 43

PostPosted: Fri Dec 19, 2008 22:46    Post subject: Can't wait to test it! Reply with quote
Can't wait to test it
_________________
Router Model: Buffalo WZR-HP-AG300H
Firmware Version: Firmware: DD-WRT v3.0-r46733 std (05/21/21)
Kernel Version: Linux 3.10.108-d11 #81419 Fri May 21 12:44:07 +07 2021 mips
graegos
DD-WRT Novice


Joined: 08 Jul 2008
Posts: 43

PostPosted: Wed Jan 14, 2009 2:11    Post subject: Reply with quote
Did anything ever materialize with this Frater?
_________________
Router Model: Buffalo WZR-HP-AG300H
Firmware Version: Firmware: DD-WRT v3.0-r46733 std (05/21/21)
Kernel Version: Linux 3.10.108-d11 #81419 Fri May 21 12:44:07 +07 2021 mips
frater
DD-WRT Guru


Joined: 07 Jun 2006
Posts: 2777

PostPosted: Wed Jan 14, 2009 7:19    Post subject: Reply with quote
Hi Graegos....

I wanted to wait a while to see if some scripts or commands could get incorporated, but it seems the devs have this on a very low priority.

Pound is incorporated in the mega-versions and USB-support has been enhanced. Are you able to use an USB-flash with ext-partition and load this as an /opt partition?

If so, I can write a tutorial that doesn't need optware....

Maybe write to brainslayer or make a ticket in TRAC?

_________________
Asus RT16N + OTRW
Kingston 4GB USB-disk 128 MB swap + 1.4GB ext3 on /opt + 2 GB ext3 on /mnt
Copperjet 1616 modem in ZipB-config
Asterisk, pixelserv & Pound running on router
Another Asus RT16N as WDS-bridge

DD-WRT v24-sp2 vpn (c) 2010 NewMedia-NET GmbH
Release: 12/16/10 (SVN revision: 15758M)
Goto page 1, 2, 3, 4, 5, 6, 7, 8  Next Display posts from previous:    Page 1 of 8
Post new topic   Reply to topic    DD-WRT Forum Index -> Broadcom SoC based Hardware All times are GMT

Navigation

 
Jump to:  
You cannot post new topics in this forum
You cannot reply to topics in this forum
You cannot edit your posts in this forum
You cannot delete your posts in this forum
You cannot vote in polls in this forum
You can attach files in this forum
You can download files in this forum