Oracle Weblogic Server: How To Configure mod_wl_ohs with Oracle HTTP Server and Oracle WebLogic Server

Configure mod_wl_ohs with Oracle HTTP Server and Oracle WebLogic Server

Oracle HTTP Server  (or any http web servers like apache , IIS)  can be used in front of Oracle WebLogic Server (WLS) or Weblogic Cluster  with the use of the Oracle Fusion Middleware 11g/12c installed mod_wl_ohs.

How To Configure mod_wl_ohs with Oracle HTTP Server and Oracle WebLogic Server


1. Check for the following configuration with WLS 10.3.4 and newer, where the first one is required for this basic setup and the second one for more advanced configurations using SSL:
  • Weblogic Plug-In Enabled
  • Client Cert Proxy Enabled
Steps to configure:
  • Login to WLS Console
  • In the Environment tab, click 'Servers'
  • Click on Adminserver - in the Configuration, General - go to Advanced section
  • Check the checkbox with the text 'WebLogic Plug-In Enabled'
  • Check the checkbox with the text 'Client Cert Proxy Enabled' if using two-way SSL
  • Save the changes and restart WebLogic Serve
2. Become familiar with your Oracle HTTP Server environment on the file system:
The module library file and configuration file is located at the following locations:
ORACLE_HOME/ohs/modules/mod_wl_ohs.so
INSTANCE_HOME/config/OHS/<component_name>/mod_wl_ohs.conf
To set the environment before administering with opmnctl, use the following examples:
UNIX:
ORACLE_HOME=/space/oracle/Middleware/Oracle_WT1; export ORACLE_HOME
ORACLE_INSTANCE=$ORACLE_HOME/instances/instance1; export ORACLE_INSTANCE
PATH=$ORACLE_INSTANCE/bin:$PATH export PATH

Windows:
set ORACLE_HOME=C:\oracle\Middleware\Oracle_WT1
set ORACLE_INSTANCE=%ORACLE_HOME%\instances\instance1
set PATH=%ORACLE_INSTANCE%\bin;%PATH%

opmnctl status -l
opmnctl stopall
opmnctl startall
3. View your default mod_wl_ohs.conf file, where you should see something like the below:

LoadModule weblogic_module "${ORACLE_HOME}/ohs/modules/mod_wl_ohs.so"

# This empty block is needed to save mod_wl related configuration from EM to this file when changes are made at the Base Virtual Host Level

<IfModule weblogic_module>

</IfModule>


4. It is important to decide on the configuration method you will use. You may manually configure the mod_wl_ohs.conf or use the /em website for this. You may also use both methods as long as you keep all configuration between the original <IfModule weblogic_module> container. You may add more <IfModule weblogic_module> containers and/or use different .conf files, but the configuration will not be displayed in the /em site. The steps in this document are going to show the actual configuration file entries within the default <IfModule weblogic_module> container within the mod_wl_ohs.conf

Single Server Configuration

5. If using a single server on Oracle Weblogic Server, modify mod_wl_ohs.conf for your Oracle WebLogic Server information as given in the below example using the /console. You may also use a deployed application which is working at http://localhost:7001/MyApplication
<IfModule weblogic_module>

#Using a single weblogic server specific to the one location
#The weblogic console is used as an example:
<Location /console>
SetHandler weblogic-handler
WebLogicHost localhost
WebLogicPort 7001
</Location>

</IfModule>

With the above configuration, when accessing the Oracle HTTP Server Listen port, this will forward /console from Oracle HTTP Server to /console on the WebLogic server at port 7001.

Cluster Configuration

6. For Oracle Weblogic Server instances in cluster, modify mod_wl_ohs.conf for your Oracle WebLogic Server information. This is where you should have an application deployed to a cluster in order to properly test:
<IfModule weblogic_module>

#Using a weblogic cluster specific to the one location
<Location /myApplication>
SetHandler weblogic-handler
WebLogicCluster localhost:8002,localhost:8003
</Location>

</IfModule>
With the above configuration, when accessing the Oracle HTTP Server Listen port, this will forward /myApplication from Oracle HTTP Server to /myApplication deployed on Oracle WebLogic Server. localhost:8002 and localhost:8003 are the listening addresses for two Managed Servers associated with a Cluster.

Combined Configuration

7. If desired to use a single server for one application but a cluster for another application, your final configuration could look like the following, as a combination of the previous two steps:
<IfModule weblogic_module>

#The weblogic console as an example to one weblogic server:
<Location /console>
SetHandler weblogic-handler
WebLogicHost localhost
WebLogicPort 7001
</Location>

#A custom application forwarding to a weblogic cluster:
<Location /myApplication>
SetHandler weblogic-handler
WebLogicCluster localhost:8002,localhost:8003
</Location>

</IfModule>
8. After making above changes you will need to restart Oracle HTTP Server. The below way is one method assuming you have set the environment variables in the earlier step:
opmnctl stopproc ias-component=ohs1
opmnctl startproc ias-component=ohs1

9. Test the addresses you have configured:
http://hostname.domainname:ohs_port/console
http://hostname.domainname:ohs_port/MyApplication

Note: At the start of this document, the wls_port was used to access Oracle WebLogic Server directly. Now the ohs_port is used to access these applications through Oracle HTTP Server. This is the objective and how to confirm mod_wl_ohs is working.
10. For a simple application, the above configurations work as stated. Adhere to advanced configuration requirements depending on your situation, applications deployed, and other business needs. See the sections below and Oracle Documentation for using Oracle Fusion Middleware Control. The /em and /console onscreen help menus are also helpful to step through specific tasks.

Customized Configuration Examples

Using Apache-based configurations within Oracle HTTP Server, there are many configuration options to fit different requirements. The section below will show a few popular options, best practices and recommendations in order to get started with different customized configurations. The same principles may be used for your own customizations. Many deal with setting a default. The advantage with setting a default is to allow applications to be deployed to Oracle WebLogic Server without a need to configure an additional Location and restart the Oracle HTTP Server. Review all examples within as there are a few different options for this customization, depending on your requirements.

I. Default Weblogic Managed Server

It may be desired to set a default server for all requests except any which already have a designated Location configured. This allows /newappname to be deployed and then accessed as /newappname without setting up a new Location in the mod_wl_ohs.conf and restarting.

In its simplest form, an example configuration would be as follows, where a designated application is deployed to a cluster, but the default is a managed server on 7001:
<IfModule weblogic_module>

#Setting a default WebLogic Server instance
SetHandler weblogic-handler
WebLogicHost localhost
WebLogicPort 7001

#A custom application forwarding to a weblogic cluster:
<Location /myApplication>
SetHandler weblogic-handler
WebLogicCluster localhost:8002,localhost:8003
</Location>

</IfModule>
The above will allow /myApplication to be served by the cluster, while all others served by the single server. Tell your users to access /newappname immediately after deployment, no Oracle HTTP Server configuration or restart necessary. Its a good method to use when testing and/or when specific applications need more specialized customizations within their own Location container.
Note:

The above configuration shows the easiest way to configure a "default" WLS instance for OHS to forward to. There is a known issue when there is a combined configuration between use of a specific location and no location. The above will work, but if the WebLogicCluster and WebLogicHost configurations are in the reverse position (the cluster being the default), the requests will always go to the cluster resulting in HTTP 404 (page not found) errors. This is a defect and the following bug has been filed:
Bug 12805286 WHEN SETTING DEFAULT LOCATION IN MOD_WL_OHS AS A CLUSTER - IT OVERRIDES OTHERS
This is scheduled to be fixed in 12.1.2. On versions before 12.1.2, there is a workaround of always using the WebLogicCluster directive, even for a single instance, such as "WebLogicCluster localhost:7001". Keeping this in mind, configuring with the below methods would actually be the overall best practice when using the Oracle HTTP Server. Other methods include the use of a default, but require an addition to the URI path to make the approach more scalable.

II. Default Context Root Location

The above may not be desired because the application names chosen may interfere unexpectedly with other locations on the Oracle HTTP Server. This also limits much flexibility you could attain with a different configuration. Setting a default Location is what you may actually want to consider as the best approach. It does not need to be a default managed server, you can configure multiple instances of this configuration. The concept is there, you may use one for the 'custom default'.

Option 1:
The following shows how a default application may be configured by using a preceding path within a separate Location designated to Oracle WebLogic Server configurations. This would be the recommended and scalable approach, especially when using the Oracle HTTP Server for multiple applications.
<IfModule weblogic_module>

#To prevent the need for new locations added for each application -
#If any request is preceded with /companypath, then use the provided instance:
<Location /companypath>
SetHandler weblogic-handler
WebLogicHost localhost
WebLogicPort 8001
PathTrim /companypath
#pathtrim is used to remove before sending to weblogic
</Location>

#A custom application forwarding to a weblogic cluster:
<Location /myApplication>
SetHandler weblogic-handler
WebLogicCluster localhost:8002,localhost:8003
</Location>

</IfModule>
The above will send /myApplication to the cluster, but all others like /companypath/Application1 and /companypath/Application2 to the single server where they are deployed as /Application1 and /Application2 on Oracle Weblogic Server. This is a great advantage because all options available for Location may be used and be specific to /companypath, keeping the specific location as your 'custom default'. Instead of using / as default, tell your users to always access /companypath/newappname after you deploy a test application.


Option 2:
Another approach is to use the MatchExpression directive:
<IfModule weblogic_module>

#To prevent the need for new locations added for each application -
#If any request is preceded with /companypath, then use the provided instance:
MatchExpression /companypath/* WebLogicHost=localhost|WebLogicPort=8001
#The above is all one line
PathTrim /companypath

#A custom application forwarding to a weblogic cluster:
<Location /myApplication>
SetHandler weblogic-handler
WebLogicCluster localhost:8002,localhost:8003
</Location>

</IfModule>

Using a Location, LocationMatch, or MatchExpression is a matter of preference, but it is a best practice to use a preceding path when using the Oracle HTTP Server in order to make a distinct differentiation allowing for more flexible and scalable configurations. MatchExpression and other general parameters available for use with Oracle HTTP Server and mod_wl_ohs are within the Plug-Guide chapter below.

III. Using Document Root Location (/)

When accessing Oracle HTTP Server, by default an index.html is accessed when not making any specific request (http://hostname.domainname/). It is sometimes desired to redirect it to an application as the default page. The following configuration in the mod_wl_ohs.conf is an example using "LocationMatch /*" and "PathPrepend" to accomplish the goal of using mod_wl_ohs to handle requests on / and forward to the application deployed on Oracle WebLogic Server:
LoadModule weblogic_module "${ORACLE_HOME}/ohs/modules/mod_wl_ohs.so"

<LocationMatch /*>
SetHandler weblogic-handler
WebLogicCluster localhost:8001,localhost:8002
#The following tells it what to access on WLS:
PathPrepend /ShoppingCart
The above will send requests to http://host:ohs_port/ to the Weblogic cluster where /ShoppingCart is deployed. Unless otherwise handled by another Location, it will also send anything unqualified to your application, e.g. http://host:ohs_port/bogus.  Note this forwards the request, it does not redirect. Users will only see what they put in the browser URL, unless your application redirects to another URL, e.g. using response.sendRedirect().
It is feasible to use "Location /something/*" and always hide everything on the backend, but may yield unexpected results related to your application. This example is meant to display a deployed Java application as a default page, not totally mask an entire application.
In this case, an application is deployed on Oracle WebLogic Server through mod_wl_ohs, which handles the pass-through processing. Without mod_wl_ohs, the same functionality exists with mod_proxy, using a ProxyPass or RewriteRule to accomplish the task of forwarding / to /anotherLocation. The following should be considered when considering ProxyPass (or RewriteRule with a pass-thru flag):
  • Mod_wl_ohs will be bypassed if using using ProxyPass (or RewriteRule with a pass-thru flag) to the WLS host and port. This is not the goal as mod_proxy will be used instead of mod_wl_ohs, which would not be supported for WLS deployed applications.
  • If using ProxyPass (or RewriteRule with a pass-thru flag) to forward to a Location on Oracle HTTP Server designated for mod_wl_ohs, you will effectively use a double proxy pass thru on the same server. This is not the goal because its not desired to use both mod_proxy and mod_wl_ohs on the same server for the same requests. This could be acceptable if you actually needed a separate Apache or OHS reverse-proxy handling requests in front of the main OHS/mod_wl_ohs.
  • If using a redirect (not pass-thru) with a RewriteRule, you can signal the client browser to make requests directly on WLS. This is not the goal if you wanted to use mod_wl_ohs. You should redirect to a new URL that will then be handled by OHS/mod_wl_ohs.

Using Virtual Hosts

Virtual Host configuration is out of scope of this document, but the folowing is a good resource since Oracle HTTP Server 11g is based on Apache 2.2:
Apache HTTP Server Version 2.2
Apache Virtual Host documentation
http://httpd.apache.org/docs/2.2/vhosts/
The following example takes the above examples one step further and configures a default page to access the application. Note in this case the module is loaded within the VirtualHost container, which is not a requirement. This may be configured where the end goal is to have multiple VirtualHosts, each with their specific configuration (outside of mod_wl_ohs.conf):

Listen 8000
NameVirtualHost hostname.domainname:8000
<VirtualHost hostname.domainname:8000>
ServerName hostname.domainname
#Load the module here for this VirtuaHost:
LoadModule weblogic_module "${ORACLE_HOME}/ohs/modules/mod_wl_ohs.so"
#You can set up one or more Location or LocationMatch, but
#the following is for the default:
<LocationMatch /*>
SetHandler weblogic-handler
WebLogicCluster localhost:8001,localhost:8002
#The following tells it what to access on WLS:
PathPrepend /ShoppingCart
</LocationMatch>
</VirtualHost>