Jed Michnowicz's Weblog

Webserver 7 and sun.com

Thursday Nov 06, 2008

This past summer, our team upgraded many of Sun's websites to Sun Webserver 7. This included www.sun.com, most of our "country" sites (uk.sun.com, cn.sun.com, etc) and most recently, www.java.com. In all, we upgraded approximately seven different server instances across 50 unique sites.

During the initial migration, we intentionally ignored some of the new features of Webserver 7. We knew the upgrade had the potential to make our life a lot easier, but we wanted to focus on stability before we started making significant changes. Over the past few months, I have fallen in love with Webserver 7 and the complex functionality you can pull off with some simple configuration tweaks. 

(One trend you will notice is that none of these hacks would be possible without the "<If>" statement.)

Selective Expires

A group requested the ability to add an "Expires" header to certain content.  As an admin, this can be a nightmare since the list of files getting the expires header will constantly change over time.  Also, before big content updates, they should temporarily disable the expires header.  Using the "lookup" function, I can empower web publishers to control this setting.

Create a control file:

expires.txt
# days till expirations (must be an integer)
/images/file.jpg       1
/js/Menu.js            14
/im/never-updates.jpg  500
/js/gl.js              1

Add the following config to:

  • Add an expires header to any matched URI
  • Process updates to the control file in real-time
 <If lookup('expires.txt',$uri)>
  ObjectType fn="set-variable" 
     insert-srvhdrs="Expires: $(httpdate($time + (lookup('expires.txt',$uri)) * 86400))"
</If>

Backend Application Hand-off

Significant portions of our sites are serviced by a back-end application.  In the old days, our only option was to map the backend URI's in a config file processed with a custom NSAPI.  While this worked, it was not an elegant solution and resulted in delays as people wanted to shuffle content between the webserver and the back-end application.  With Webserver 7, we can perform a file stat to determine if we should serve content locally with webserver, or send the request to the backend.

<If not -f "$docroot/$path" and not -f "$docroot/$path/index.html" and not -f "$docroot/$path/index.jsp">
     NameTrans fn="map" from="/" name="passthrough-backend" to="http:/"
</If>

URI Rewrites

Some of our sites share the docroot for http and https content.  The SEO czars wanted to control the crawling of both http and https content.  To enable this, we used the "restart" function which is very similar to an apache "mod_rewrite".

 <Client security="true">
  <If $uri =~ '^/robots.txt'>
    NameTrans fn="restart" uri="/robots-ssl.txt"
  </If>
</Client>

Now we can restrict robots from crawling the https content. 

We also use restarts to maintain some legacy URL's that cannot be redirected.  Previously, we used a custom NSAPI module for this functionality which we happily EOL'd.

[0] Comments
Like this post? del.icio.us | furl | slashdot | technorati | digg
Comments:

Post a Comment:
  • HTML Syntax: NOT allowed