Novell Home

How to use Branch Office to Replicate an Intranet Web Site and Redirect Users to Nearest Copy

Novell Cool Solutions: Feature
By Florian Deckert

Digg This - Slashdot This

Posted: 31 Aug 2005
 

problem:

"Very well done. Provides a complete example for replicating an intranet website and directing users to the nearest server."

--Aaron Gresko
Product Specialist
Novell, Inc.

Provide Akamai-like replicated web sites on NetWare 6.5 servers.

How to use the Branch Office NetWare servers to replicate the central intranet, and automatically redirect users to the nearest copy when they call the intranet.

solution:

  1. Distribute files

    First we need to distribute files from the central server (say a Linux one) to a NetWare volume (VOL1:/Intranet)

    On the central server create a RSYNC daemon with the intranet folder in file "/etc/rsyncd.conf"

    [INTRANET]

      path = /www/srv/htdocs
      comment = our intranet
      read only = yes
      hosts allow = myserver.remote.corp

    On the remote NetWare server you can start a rsync client:
    rsync -arvz --delete myserver.central.corp::INTRANET --volume=VOL1: /intranet

    Add this command in sys:/etc/crontab to do it daily or distribute it thru ZENworks for Servers.



  2. Setup an apache virtual web server

    On your remote NetWare you have to create a virtual server to host the intranet files.

    change the file sys:/apache2/httpd.conf

NameVirtualHost myipaddress:80

<VirtualHost myipaddress:80>
	DocumentRoot vol1:/intranet
	ServerName intranet.remote.corp
	CustomLog "|SYS:/APACHE2/BIN/ROTLOGS.NLM  /apache2/logs/intranet_log 50M" common
  </VirtualHost>
  1. Being redirected

    This is the tricky part as you want your users to call the main web server page, and be automatically redirected to our local (nearest) NetWare copy depending on the IP address (kind of geo ip).

    1. Getting the caller ipaddress in apache

      With JavaScript you can't get the caller ip, so we have to use a server-side include (SSI).

      change the file sys:/apache2/httpd.conf

    <Directory "doi:/public">
        Options +includes
      </Directory "doi:/public">
      DirectoryIndex index.shtml index.html index.html.var index.shtml index.php
    
    AddType text/html .shtml
    AddOutputFilter INCLUDES .shtml

    Now create an index.shtml at the web server root folder /srv/www/htdocs/index.shtml that includes the caller ip in a java script :

     <script LANGUAGE="JavaScript">
      var ip = '<!--#echo var="REMOTE_ADDR"-->';


    1. Redirect the caller to the nearest copy

      Now that we have the caller ipaddress, we can use a bit of javascript to decide if this caller does have a copy on site to be redirected to. Of course we can't just redirect to the root of the web server, as this is going to trigger the index.shtml file. So we need to redirect to a static index.html file.

    var ips = ip.split (".");
    var domainc = ips[0] + "." + ips[1] + "." + ips[2];
    
    if (domainc == 192.168.0) {
      window.location = "http://intranet.remote.corp/index.html";
    } else {
      window.location = "http://intranet.central.corp/index.html";
    }

  2. Conclusion

    Using rsync, apache2, SSI & javascript, we can easily provide our users a fast experience of a static intranet web server using the branch office servers. Users don't even know what server they are browsing as they are transparently redirected.

This article is only about replicating static web pages, but we also managed to replicate our main LAMP (Linux Apache MySql PHP) server to nearly 20 remote NetWare servers. :-) This will be in the next article.

example:

© 2014 Novell