Friday, January 27, 2017

Serve static web content from Oracle Traffic Director

A colleague of mine, Mark Mundy, recently got a query about using Traffic Director to server static content.  Following on from that he put together this example of how it can be achieved.
Oracle Traffic Director version 12c (12.2.1) does support the serving of static content alongside the existing capability to cache content. More details on how this is achieved can be found here:
With this confirmed, I then utilised the current version of Java Cloud Service on an Oracle Cloud Machine to try out this capability. I created a simple WLS Service based upon 12.2.1 Enterprise Edition and selected to utilise a load balancer for my 2 manged server cluster.  This ensured as part of the service I had provisioned a single instance of OTD 12.2.1 that I could then use to serve static content. 
For this very simple test I created very basic html file that referenced an image file and my plan was to copy these two assets to the local storage of the OTD virtual machine hosting OTD. Below is the html file I used and you can see the referenced image that was stored alongside it. I created a basic index.html to ensure the file was servers when the default uri was accessed.
<TITLE>OTD is great!</TITLE>
<CENTER><IMG SRC="stormtrooper.jpg" ALIGN="BOTTOM"> </CENTER>
<H1>This is being served by Oracle Traffic Director</H1>
<a href="">OTD Admin Guide : 7.11 Content Serving</a>
is where you will find details on how to do this!

OTD executes under the oracle user and so I created a sub directory under the oracle home to store the html and the image

-bash-4.1$ pwd
-bash-4.1$ ls
index.html stormtrooper.jpg
With the static content in place I now needed to make configuration changes to OTD in order to enable it to be able to served.  Logging into the Fusion Middleware Control UI (OTD 12.2.1’s administration home) from within the JCS UI, I navigated to the OTD configuration already provisioned. I selected the single virtual server associated with the configuration and selected the ‘Content Serving’ section

Content Serving tab in Fusion Middleware Control UI

Here I selected to ‘Create …’ a new content rule
In the dialogue presented I added the following:
Rule to specify location of static content

Once created there is the opportunity to go back into the rule and edit it further should you need to. You can for example allow directory listing if desired.
The rule is immediately activated in the running instance and so it is now possible to use a browser to request OTD to serve the html page.
This resulted in OTD responding with the default index.html from the directory associated with the rule created. The resulting page looking a little like this below.

Web content delivered from OTD