Page 1 of 3 123 LastLast
Results 1 to 15 of 37

Thread: How to run two webservers

  1. #1

    Thumbs up How to run two webservers

    Hi,

    I've seen several questions regarding how to setup a second webserver on the wl500g so I thought I'd share my experiences on this matter.

    First you need to start the webserver. Add the following line to /usr/local/init/post-boot:

    Code:
    busybox_httpd -c /mnt/usbfs/etc/httpd.conf -p 8080 -r "My dungeon" -h /mnt/usbfs/web
    Here' s the documentation fot the busybox webserver
    /*
    * httpd implementation for busybox
    *
    * Copyright (C) 2002,2003 Glenn Engel <glenne@engel.org>
    * Copyright (C) 2003 Vladimir Oleynik <dzo@simtreas.ru>
    *
    * simplify patch stolen from libbb without using strdup
    *
    * This program is free software; you can redistribute it and/or modify
    * it under the terms of the GNU General Public License as published by
    * the Free Software Foundation; either version 2 of the License, or
    * (at your option) any later version.
    *
    * This program is distributed in the hope that it will be useful,
    * but WITHOUT ANY WARRANTY; without even the implied warranty of
    * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
    * General Public License for more details.
    *
    * You should have received a copy of the GNU General Public License
    * along with this program; if not, write to the Free Software
    * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
    *
    ************************************************** ***************************
    *
    * Typical usage:
    * for non root user
    * httpd -p 8080 -h $HOME/public_html
    * or for daemon start from rc script with uid=0:
    * httpd -u www
    * This is equivalent if www user have uid=80 to
    * httpd -p 80 -u 80 -h /www -c /etc/httpd.conf -r "Web Server Authentication"
    *
    *
    * When a url contains "cgi-bin" it is assumed to be a cgi script. The
    * server changes directory to the location of the script and executes it
    * after setting QUERY_STRING and other environment variables.
    *
    * The server can also be invoked as a url arg decoder and html text encoder
    * as follows:
    * foo=`httpd -d $foo` # decode "Hello%20World" as "Hello World"
    * bar=`httpd -e "<Hello World>"` # encode as "&#60Hello&#32World&#62"
    * Note that url encoding for arguments is not the same as html encoding for
    * presentation. -d decodes a url-encoded argument while -e encodes in html
    * for page display.
    *
    * httpd.conf has the following format:
    *
    * 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
    * /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/
    * .au:audio/basic # additional mime type for audio.au files
    *
    * A/D may be as a/d or allow/deny - first char case insensitive
    * Deny IP rules take precedence over allow rules.
    *
    *
    * The Deny/Allow IP logic:
    *
    * - Default is to allow all. No addresses are denied unless
    * denied with a D: rule.
    * - Order of Deny/Allow rules is significant
    * - Deny rules take precedence over allow rules.
    * - If a deny all rule (D:*) is used it acts as a catch-all for unmatched
    * addresses.
    * - Specification of Allow all (A:*) is a no-op
    *
    * 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 a 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.
    *
    *
    * 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.
    *
    */
    That's the easy part. What is a bit more trickier is to configure iptables so that you can access your webserver from the WAN. I want this webserver to be used when I browse to my external IP, e.g. http://sesamebike.dyndns.org (bogus url, don't click). Still I want the wl500g admin webserver to be used if I browse to http://my.router. Finally, I don't want the external web server to be accessable on port 8080, only port 80.

    Edit the /usr/local/init/post-firewall and add the following:

    Code:
    /usr/sbin/iptables -t nat -I PREROUTING -p tcp -d "$2" --dport 80 -j DNAT --to "$2":8080
    /usr/sbin/iptables -t nat -D PREROUTING -i "$1" -p tcp --dport 80 -j DROP
    /usr/sbin/iptables -t nat -I PREROUTING -i "$1" -p tcp --dport 8080 -j DROP
    /usr/sbin/iptables -A INPUT -i "$1" -d "$2" -p tcp --syn --dport 8080 -j ACCEPT
    Remember to save your changes to the flash using flashfs save and flashfs commit.

    Hopefully this will get you started. At least this setup worked for me on Oleg's excellent 1.7.5.9-5 firmware.

    Cheers!
    Last edited by sesamebike; 25-08-2004 at 12:17. Reason: Sorry, forgot to tell you which firmware. This was done on Oleg's excellent 1.7.5.9-5 firmware.

  2. #2
    Join Date
    Apr 2004
    Location
    Netherlands
    Posts
    1,308
    Nice, thanks!

    Busybox_http can also run cgi-bin scripts:

    - Create a directory named: `cgi-bin` in the `wwwroot` directory.
    - Place one or more executable (`chmod +x scriptname`) Bash script(s) in the `cgi-bin` directory.
    - Call the script using `http://my.router:8080/cgi-bin/scriptname` in the address toolbar of your browser.
    - Enjoy the output from your script

    All scripts in the subdirectorys below cgi-bin are also executable. If your script is not executable or is not a runnable script the webserver returns: 404 (page not found).

    One example of what you can do with Bash scripting is below. It shows info from your router such as uptime, running services, free disk space, etc:
    Code:
    #!/bin/sh
    
    echo "<html>"
    echo "<body bgcolor=#5555aa>"
    echo "<h2>System info for Asus WL-500g home gateway router</h2>"
    
    echo "<hr>"
    echo "<b>Uptime:</b><br>"
    echo "<pre>"
    uptime
    echo "</pre>"
    echo "<hr>"
    echo "<b>Harware and firmware versions:</b><br>"
    echo "<pre>"
    cat /mnt/ramfs/etc/linuxigd/general.log
    echo "</pre>"
    echo "<hr>"
    echo "<b>CPU info:</b><br>"
    echo "<pre>"
    cat /proc/cpuinfo
    echo "</pre>"
    echo "<hr>"
    echo "<b>Memory Info:</b><br>"
    echo "<pre>"
    cat /proc/meminfo
    echo "</pre>"
    echo "<hr>"
    echo "<b>Partitions:</b><br>"
    echo "<pre>"
    cat /proc/partitions
    echo "</pre>"
    echo "<hr>"
    echo "<b>Disk usage:</b><br>"
    echo "<pre>"
    df
    echo "</pre>"
    echo "<hr>"
    echo "<b>Services:</b><br>"
    echo "<table>"
    
    echo "<tr>"
    echo "<td>Stupid FTP server</td>"
    echo "<td>-</td>"
    if [ `ps -ax | grep -c stupid-ftpd` -gt 1 ]
    then
            echo "<td>Running</td>"
    else
            echo "<td>NOT running</td>"
    fi
    echo "</tr>"
    
    echo "<tr>"
    echo "<td>giFT daemon</td>"
    echo "<td>-</td>"
    if [ `ps -ax | grep -c ld.so.1` -gt 1 ]
    then
            echo "<td>Running</td>"
    else
            echo "<td>NOT running</td>"
    fi
    echo "</tr>"
    
    
    echo "<tr>"
    echo "<td>Dropbear SSH daemon</td>"
    echo "<td>-</td>"
    if [ `ps -ax | grep -c dropbear` -gt 1 ]
    then
            echo "<td>Running</td>"
    else
            echo "<td>NOT running</td>"
    fi
    echo "</tr>"
    
    echo "<tr>"
    echo "<td>Traffic counter</td>"
    echo "<td>-</td>"
    if [ `ps -ax | grep -c iptraf` -gt 1 ]
    then
            echo "<td>Running</td>"
    else
            echo "<td>NOT running</td>"
    fi
    echo "</tr>"
    
    echo "</table>"
    echo "<hr>"
    echo "</body>"
    echo "</html>"
    Last edited by Styno; 25-08-2004 at 12:49.

  3. #3
    Join Date
    Dec 2003
    Location
    Russian Federation
    Posts
    8,356
    Guys please make a WIKI page, otherwise this will got lost - nobody is using search as seems.
    Also, some hints - small web server pages as well as httpd.conf file could be stored in the flashfs also.
    flashfs rocks. At the moment that's the easiest way for using both stock firmware features and a customizations. sveasoft does not offer thing like this in their firmwares. openwrt has no web iface and is completely different. I'm really proud of my invention.

  4. #4
    Join Date
    Apr 2004
    Location
    Netherlands
    Posts
    1,308
    Quote Originally Posted by Oleg
    Guys please make a WIKI page, otherwise this will got lost - nobody is using search as seems.
    aye, aye captain . Though it might be useful to let it stay here so all the newbies have to learn how-to use the search
    Also, some hints - small web server pages as well as httpd.conf file could be stored in the flashfs also.
    Yes, the webpages can be stored anywhere; Flashfs, USB stick, USB HDD, compiled into the firmware...
    flashfs rocks. At the moment that's the easiest way for using both stock firmware features and a customizations. sveasoft does not offer thing like this in their firmwares. openwrt has no web iface and is completely different. I'm really proud of my invention.
    The flashfs method certainly is a great `invention`. Nobody's disagreeing with that!

  5. #5
    Quote Originally Posted by Oleg
    flashfs rocks. At the moment that's the easiest way for using both stock firmware features and a customizations. sveasoft does not offer thing like this in their firmwares. openwrt has no web iface and is completely different. I'm really proud of my invention.
    It's a neat way to get a more-or-less-persistent directory tree.
    But the lffs thingy in OpenWRT gets you real persistent storage, which is pretty convenient at times (you basically don't ever need to flash a new firmware any more). Losing the web-config is a bummer, tho, especially at the beginning. I'm very comfortable with Unix-style administration, but I still considered it important that when I switched to your custom firmware, everything was going to work "just as before".
    Now that I've been using it for a while and I've added my own config tweaks, I'd rather get rid of the web-config (especially with its "password in the clear").

    If it were possible to have your custom firmware but with squashfs replaced by lffs2 I'd be pretty happy.

  6. #6
    Join Date
    Apr 2004
    Location
    Netherlands
    Posts
    1,308
    I assume you mean jffs2 ...

    jffs2 might be interesting for replacing the flashfs partition for 2 reasons:
    - Just edit a config file and forget about it , no need for flashfs save and commit commands.
    - No need to check maximum flash space before commiting anymore.

    It's no option to replace the squashfs partions containing the firmware with jffs2 because the compression provided by squashfs (Unless jffs2 provides compression as well of course).
    Last edited by Styno; 25-08-2004 at 16:30.

  7. #7
    Join Date
    Dec 2003
    Location
    Russian Federation
    Posts
    8,356
    Quote Originally Posted by monnier
    If it were possible to have your custom firmware but with squashfs replaced by lffs2 I'd be pretty happy.
    Forget about this. There are two reasons: 1) jjfs requires much moe free space than we have (currently 40k); 2) jffs has lower comprression ratio, comparable with cramfs.

  8. #8
    i am using the 1.8.1.7 firmware . i want to setup a webserver. but the telnetd does not included. so i use the busybox as discussed in other thread. however,
    1) the telnetd is not password protected.
    2) i can not find the path /usr/local/init.

    any suggestion that what should i do.

  9. #9
    Join Date
    Dec 2003
    Location
    Russian Federation
    Posts
    8,356
    Quote Originally Posted by chancho
    any suggestion that what should i do.
    Downgrade to 1.7.5.9-5.

  10. #10
    hello, this post is interessing me..

    i have oleg's firmware 1.7.5.9-5 but i can't seem to find the path /usr/local/init

    i am getting as far as the /usr/local and there i stop.. i can't find the init folder

    the only to folder i got under /usr/local is those : etc and root.

    hope there is someone that can help me with this.

    Kind Regards

    NIGHTCD

  11. #11

    About the /usr/local/init

    Hi chancho and NIGHTCD!

    You both asked why you are not seeing the /usr/local/init folder. That's because you need to create it yourself. Please read Oleg's documentation for the 1.7.5.9-5 firmware. It's located at http://wl500g.dyndns.org. Be sure to read the Tips and Tricks sektion where you'll find detail instructions on how to create the /usr/local/init folder

    Happy hacking!

  12. #12
    Join Date
    Apr 2004
    Location
    Netherlands
    Posts
    1,308
    Quote Originally Posted by NIGHTCD
    hello, this post is interessing me..

    i have oleg's firmware 1.7.5.9-5 but i can't seem to find the path /usr/local/init

    i am getting as far as the /usr/local and there i stop.. i can't find the init folder

    the only to folder i got under /usr/local is those : etc and root.

    hope there is someone that can help me with this.

    Kind Regards

    NIGHTCD
    Look at the Flashfs-boot page in the WIKI section: It contains detailed information on how-to setup post-boot configurations.

    http://wiki.wl500g.info/index.php/FlashfsBoot

  13. #13
    Thanks :-)

    NIGHTCD

  14. #14
    (Sorry, I meant jffs2. I just can't get to terms with their choice of "journalling" in the name, even though the first line explains clearly that jffs2 is a "log-structured" filesystem (which is similar to a journalling filesystem, but is not the same)).

    Quote Originally Posted by Oleg
    Forget about this. There are two reasons: 1) jjfs requires much moe free space than we have (currently 40k); 2) jffs has lower comprression ratio, comparable with cramfs.
    Reading some jffs2 mailing-lists, I got the impression that it can still work even with very low free space (although inefficiently, but we don't necessarily care if we only write to it for config purposes, and keep logfiles in ramfs).

    But the compression ratio is the killer. Damn!
    BTW, I had looked around before to get some data about the relative compression efficiency between squashfs, cramfs, jffs2, ... but couldn't find anything: where
    did you get your info from?

  15. #15
    Join Date
    Dec 2003
    Location
    Russian Federation
    Posts
    8,356
    Quote Originally Posted by monnier
    But the compression ratio is the killer. Damn!
    BTW, I had looked around before to get some data about the relative compression efficiency between squashfs, cramfs, jffs2, ... but couldn't find anything: where
    did you get your info from?
    Tried myself. jffs2 package also contains something like mkjffs2 - can't remember how it's named exactly.

Page 1 of 3 123 LastLast

Similar Threads

  1. 2 computers, 2 webservers, 1 ip, 2 domain-names
    By Djuri in forum WL-500g Q&A
    Replies: 1
    Last Post: 09-06-2004, 06:26

Tags for this Thread

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •