Saturday, January 13, 2007

OracleAS rewrite/redirect URL to internal machine hostname

Usually when we setup a machine, we’ll simply give a hostname for the machine. Then we install OracleAS on it.

When it goes live, we’ll assign a new Domain Name to point to this machine. Hence, this machine has 2 names. Internally it is machine_hostname.domain.com and externally it is host.internet.com.

From Internet when we access this machine, here comes a strange behaviour: when we login OracleAS EM (Enterprise Manager) or perform JSP/Struct/JSF Redirect in our web application, the internal machine hostname is shown up in browser. Hence the browser shows “Page cannot be displayed”.

Amazing. What’s wrong? What happens inside JSP/Struct/JSF Redirect?

Here is the culprit:

vi $ORACLE_HOME/Apache/Apache/conf/httpd.conf”.

You see the following information:


ServerName machine_hostname.domain.com


# UseCanonicalName: (new for 1.3) With this setting turned on, whenever
# Apache needs to construct a self-referencing URL (a URL that refers back
# to the server the response is coming from) it will use ServerName and
# Port to form a "canonical" name. With this setting off, Apache will
# use the hostname:port that the client supplied, when possible. This
# also affects SERVER_NAME and SERVER_PORT in CGI scripts.
UseCanonicalName On


Observation is,
1) ServerName is hardcoded with internal machine hostname.
2) Read the explanation of UseCanonicalName, Apache use ServerName to construct a self-referencing URL.

So, we need to set UseCanonicalName off, then Apache will use the hostname:port that the client supplied.

Problem solved. Mission accomplished.

1 comment:

Niall Mc Phillips - Long Acre said...

Very useful post. Solved my problem with the host name changing in the URL. Thanks. Niall.