IBM Support

How to serve static files from both IBM HTTP Server and an application in WebSphere Application Server

Question & Answer


Question

How can I configure IBM HTTP Server (IHS) to serve some static files that would otherwise be handled by WebSphere Application Server via the Web Server plug-in?

Cause

  • On WepSphere Application Server traditional, the "fileServingEnabled" property in ibm-web-ext.xmi file controls whether the plugin-cfg.xml is generated with patterns that capture an entire context root or individual servlets and file names with special extensions like *.jsp.
  • On WebSphere Liberty, the plugin-cfg.xml always uses patterns that forward the entire context root.

Answer

If you want to serve any static files (JPG, GIF, CSS, JS, etc) from the application server you must use fileServingEnabled="true" in the ibm-web-ext.xmi file. 
To selectively serve some subset of static files directly from IBM HTTP Server, you must perform several steps:
In the following example, application App1.war is deployed to context root /app1 and contains large static files such as /app1/scripts/framework.js.  Identify some static files in your own application by reviewing the IHS access log or your browsers Web Developer tools.
Configuration:
  1. Create a subdirectory called "static" under the IHS DocumentRoot directory, for example /opt/IBM/HTTPServer/htdocs/static/
  2. Create a subdirectory under "static" for the application context root, for example /opt/IBM/HTTPServer/htdocs/static/app1
  3. Selectively extract the static content you want to offload from App1.war into /opt/IBM/HTTPServer/htdocs/static/app1
    The final extracted paths should include the context root and any intermediate directories, for example /opt/IBM/HTTPServer/htdocs/static/app1/scripts/framework.js
  4. Configure IHS to probe the new directory for static content, bypassing the Application Server. Append the following snippet to httpd.conf or the virtual host that handles requests for "App1"
# Append to bottom of httpd.conf or appropriate <virtualHost>

RewriteEngine ON

# If the file exists under static/, rewrite it
RewriteCond %{DOCUMENT_ROOT}/static/$1 -d [OR]
RewriteCond %{DOCUMENT_ROOT}/static/$1 -f
# Optional: Limit offload to specific file extensions
RewriteCond %{REQUEST_URI} \.(png|gif|css|js)$ [NC]
# Substitution required: Change /app1 to your context root
RewriteRule (^/app1/.*) /static/$1 [PT,E=skipwas]

# Make sure /static/ is not matched to a context root of `*` for another app
RewriteRule ^/static/ - [E=skipwas]

Result:

Requests such as /app1/scripts/framework.js are now be served directly by IHS. 

To verify the file was served by IHS
  1.  Create a diagnostic log file in the same section of httpd.conf:
     
    CustomLog logs/static.log "%f %{RH}e" 
    
  2. Request a candidate static resource, such as /app1/scripts/framework.js
  3. Review the last two columns in logs/static.log under the IHS root
    # Example entry for content served by the AppServer:
    /app1/scripts/framework.js (mod_was_ap22_http.c/0/handler)
    ^^ original URL             ^^ WAS plug-in
    # Example entry for content served by IHS
    /opt/IBM/HTTPServer/htdocs/app1/scripts/framework.js (core.c/0/handler)
    ^^ filesystem path                                    ^^ (Apache) core file handling

[{"Business Unit":{"code":"BU059","label":"IBM Software w\/o TPS"},"Product":{"code":"SSEQTJ","label":"IBM HTTP Server"},"ARM Category":[{"code":"a8m50000000Cd10AAC","label":"IHS"}],"ARM Case Number":"","Platform":[{"code":"PF002","label":"AIX"},{"code":"PF010","label":"HP-UX"},{"code":"PF016","label":"Linux"},{"code":"PF027","label":"Solaris"},{"code":"PF033","label":"Windows"}],"Version":"All Version(s)","Line of Business":{"code":"LOB45","label":"Automation"}}]

Document Information

Modified date:
30 June 2020

UID

swg21508890