Article: Domino & Apache »
FERDY CHRISTANT - MAY 24, 2004 (10:09:56 PM)
This article explains an easy way to use Apache as a proxy for all your other servers running on the same box.
Currently, there's many different kinds of web servers in the market. Each one has their own strengths and weaknesses. Sometimes you might need to combine different servers and use the best of many worlds. One common server to enrich a Domino environment with is Apache, the awarded, free, lightning-fast open source HTTP server used for hosting about 90% of all the world's websites.
Maybe even that's not enough. Maybe you need to integrate your Domino environment with a Websphere server. And perhaps it doesn't stop there, what if you also need a PHP server? And, what if you need to run all these on one box, with one network card? Read on...
The classic way to integrate Apache with Domino is to let Apache use the standard HTTP port 80 and reroute all Domino traffic to the Domino HTTP server, which you configure to run on port 81, for instance. The rerouting is done using a rewrite rule in the Apache config file, such as this one:
RewriteRule ^(.*).nsf(.*) http://localhost:81$1.nsf$2 [P]
The rule above states that any incoming URL that has the .nsf pattern in it, will be rerouted to the Domino HTTP task, running on port 81. This is everything but water-proof:
- To take care of other Domino extensions, we need to add rules that handle .ntf, .ns4, .ns5, etc. extensions as well.
- To make sure files we refer to in the Domino server's file directory are handled by Domino, and not Apache, we need to make additional rules for icons, the domjava dir and others.
- Domino URLs that use a replica ID to refer to a Notes database will not work, unless you manually add a rewrite rule for each and everyone of them. A worst practice at best, server configuration and applications need to be loosely coupled at all times.
- Any of the many rewrite rules you would have to create mentioned above can potentially conflict with the internal working of another web server if you're in for some bad luck.
The solution to all of the above problems is amazingly simple and has been build into Apache since version 1.1: virtual hosts. Using virtual hosts you can redirect traffic to the right server using the domain, subdomain, IP or any pattern you can come up with. The remainder of this article explains a simple setup, which stacks multiple HTTP servers in a transparent way.
By default, the Domino HTTP task runs on port 80. Because Apache will take care of our incoming HTTP traffic on port 80, we need to adjust the Domino HTTP port to 81, or any other free port.
In order to set the Domino HTTP task to run on port 81, do the following:
- Open your server document in edit mode
- Go to the tab "ports", sub tab "Internet Ports", sub tab "Web".
- Fill out "81" in the field "TCP/IP port number".
- Save the server document
- Restart the HTTP task by entering "tell http restart" at the server console
This article will not explain how to install Apache. You can read all about it on apache.org. Installing Apache generally doesn't take longer than a few minutes and is straight-forward. Plus, by default, Apache runs on port 80, which is what we need.
To use Apache as a proxy and rewrite engine, we need to make sure the Apache server loads certain modules. Make sure that at least the following lines are in your Apache httpd.conf configuration file:
LoadModule proxy_module modules/mod_proxy.so
LoadModule proxy_http_module modules/mod_proxy_http.so
LoadModule rewrite_module modules/mod_rewrite.so
If these lines are already there, make sure you remove the "#" character in front of it. If they are not there at all, add them as above.
Note:The location of the load module lines within the Apache config file differs per version.
Apache virtual hosts
Now for the interesting part. In this case setup we have Domino running on port 81, Websphere on port 9001, and Apache on port 80. We like to reroute all traffic coming from domino.ferdychristant.com to the Domino HTTP task, all traffic from was.ferdychristant.com to the Websphere server, and all other traffic to the default server, which is the Apache document root. Furthermore, we obviously do not want to enter a URL with a port number, nor do we want users to bookmark a rewritten URL that includes a port number. In short, users should not enter or see a port number in any URL.
All of the above requirements can be implemented by simply adding the following lines to the Apache httpd.conf file:
RewriteRule ^/(.*) \http://domino.ferdychristant.com:81/$1 [P]
RewriteRule ^/(.*) \http://was.ferdychristant.com:9001/$1 [P]
We have defined two virtual hosts and rerouted two subdomains to the right server. In each virtual host definition, we can define the incoming URL pattern, as well as the rewrite rule that routes it to the right port, directory, (sub)domain or IP. The "[P]" behind each rewrite rule sets Apache to proxy the URL, which takes care of our requirement of transparent URLs without explicit port numbers. The following scheme shows how this works:
- All incoming traffic on the box comes in at port 80.
- The Apache proxy/rewrite engine handles the incoming request and proxies it to the right web server/port.
- The appropriate web server handles the incoming request.
- The appropriate web server generates a response, if any. This response will arrive again at the Apache proxy engine who does a reverse proxy action on it.
- The response will be sent back to the user who requested it.
ConclusionUsing Apache's virtual hosts, you can redirect incoming traffic to the appropriate web server on your box, fail-safe, transparent for the end user, and with just one rewrite rule. Compared to the classic Domino & Apache setup, the only difference is that we separate incoming traffic by (sub)domain, IP, directory or hostname. With some proper URL management, you should be able to apply this technique in any situation.
No longer do you need to write new rewrite rules as soon as you need to deploy a new application on Domino, or when a new extension is introduced. No longer do you need to add rewrite rules for coping with the internal working of your web server, such as icon directories and such. No longer do you need to worry about potential URL conflicts between different web servers. Want to add a new server to the box? Simply add one virtual host entry. Summarized, this is as good as it gets.
Tip: Additionally, you can always refine your URL policy within Domino using the Internet configuration documents that came new in R6.