Configuring Laszlo to run through IIS using mod_jk/isapi_redirect.dll
Summary for techies
This article describes how to setup Laszlo on Apache Tomcat to work through IIS, using mod_jk to talk between them. It involves downloading the isapi_redirect.dll from Apache's site, configuring IIS to use the .dll and creating or editing some Tomcat configuration files. It may or may not involve a restart of the IIS service depending on your environment.
Other than the normal setup of mod_jk/isapi_redirect.dll described in the below Apache links, you need to add a connector to your server.xml file for AJP, on the same port as the worker you describe in your workers.properties file.
Many Windows-based organisations will have IIS running their ASP/PHP website beautifully, but would also like to incorporate Laszlo technology into their website. The easiest solution is to compile a Laszlo application into a Flash file or DHTML package, then place it in your IIS web tree. That's called 'solo' mode and whilst being the easiest to deploy has some limitations compared with 'proxied' mode where you run the scripts directly from the Laszlo server.
The issue with proxied mode is that IIS can't process Laszlo scripts directly, Laszlo is Java based and needs to run in a Java server such as Tomcat or JBoss. However there is a connector 'mod_jk' from the Apache Foundation, which can bridge the gap between Tomcat and IIS. This article is about setting up that bridge, so that when IIS sees a request for an .lzx file, it passes the request to Tomcat and returns the result to the browser.
An advantage of going through IIS or Apache is that if you have a scripting language such as PHP that uses sessions authentication, your Laszlo scripts can use the same session. This means you know who the person is using the Laszlo script and can customise it to them. For example it has been used to limit options available depending on the user's security level.
To start off with, Tomcat is a Java server called a servlet container. It takes http requests just like IIS and the Apache HTTPD server, does some processing and gives a response. It can be a webserver on its own for Java Server Pages (JSP) or coupled with another webserver like IIS or Apache.
Though not addressed in this article it is possible to configure Tomcat for load balancing on various machines. Laszlo doesn't necessarily have to be installed on the same machine as IIS for this concept to work, as long as your isapi_redirect.dll is available to the IIS machine. If you were going to attempt that setup, at a guess you would change the host from 'localhost' to something else in your worker.properties file and update the registry settings.
Most of this information came from these very helpful and better written links:
- The Apache Tomcat Connector - Reference Guide - Configuring IIS
- The Apache Tomcat Connector - Webserver HowTo - IIS Setup
- The Apache Tomcat Connector - Generic HowTo - Workers Howto
- Tomcat Wiki - Tomcat and IIS Howto
This link may also be helpful:
What you need
- administrator privileges on the machine
- IIS installed
- Laszlo installed within Tomcat (check that it works on its own first by going to port 8080 on your local machine!)
- isapi_redirect.dll/mod_jk from the Apache Tomcat website
The isapi_redirect.dll connector allows a request from a webserver like IIS or Apache to be made to Tomcat, then the response returned to the browser. Processing of the entire file is passed to Tomcat and the result sent straight to the browser, so this isn't really for processing part of a PHP script, then processing a bit of Laszlo then going back again to PHP.
The system tested was running Windows XP Professional SP2 with IIS 5.1, OpenLaszlo 3.3.3 / 4.0.0 / 4.0.2 / 4.0.12 bundled with Tomcat 5.0.24. The basic principles should apply to IIS6 on Windows Server 2003 and also using the .war version of Laszlo.
New Registry Keys
When IIS calls isapi_redirect.dll, it checks for a local config file in the same directory as the dll. If the config file isn't there, it checks the registry (the registry is the normal way to configure it).
Please see Apache's mod_jk-IIS setup page for an explanation of the registry settings.
If you wish to increase the logging in the jk_iis.log file, set it to 'debug' instead of 'info'.
Under "HKEY_LOCAL_MACHINE\SOFTWARE\Apache Software Foundation\Jakarta Isapi Redirector\1.0" create the following keys:
|log_file||C:\Program Files\OpenLaszlo Server 4.0.2\Server\tomcat-5.0.24\conf\jk_iis.log|
|worker_file||C:\Program Files\OpenLaszlo Server 4.0.2\Server\tomcat-5.0.24\conf\workers.properties|
|worker_mount_file||C:\Program Files\OpenLaszlo Server 4.0.2\Server\tomcat-5.0.24\conf\uriworkermap.properties|
New IIS virtual directory
A virtual directory is needed within IIS to the isapi_redirect.dll file. Although it can probably be called something else, I called it 'tomcat' and had it referring to C:\Program Files\OpenLaszlo Server 4.0.2\Server\tomcat-5.0.24\conf
New IIS ISAPI filter
Under the website properties, go to the ISAPI Filters tab and add a new filter called 'tomcat'.
The filter should go to:
C:\Program Files\OpenLaszlo Server 4.0.2\Server\tomcat-5.0.24\conf\isapi_redirect.dll
I changed or created three configuration files. All of them were in C:\Program Files\OpenLaszlo Server 4.0.2\Server\tomcat-5.0.24\conf. Please see below for the changes to each file.
server.xml is the main setup file for Tomcat that specifies virtual hosts, connectors and the like.
I added a line to the standard Laszlo setup for the connector on port 8009. Please see the example file below.
The original connector for port 8080 I left intact.
<Server port="8005" shutdown="SHUTDOWN"> <Service name="LPS"> <Connector port="8009" enableLookups="false" redirectPort="8443" protocol="AJP/1.3" /> <Connector port="8080" /> <Engine name="LPS" defaultHost="localhost"> <Logger className="org.apache.catalina.logger.FileLogger" /> <Host name="localhost" appBase="webapps" /> </Engine> </Service> </Server>
- if the user goes to http://hostname:8080/lps-4.0.2/my-apps/sample_app/src/sample.lzx they will only be conversing with Tomcat on port 8080 without involving IIS
- if the user goes to http://hostname/lps-4.0.2/my-apps/sample_app/src/sample.lzx IIS will see the request and pass it on to Tomcat using isapi_redirect.dll talking on port 8009
The workers.properties file I created in C:\Program Files\OpenLaszlo Server 4.0.2\Server\tomcat-5.0.24\conf
The workers file tells Tomcat about connectors or 'workers', which port, host and protocol they are working on (not sure how to explain this, maybe a Tomcat expert could explain better).
I created the uriworkermap.properties file in C:\Program Files\OpenLaszlo Server 4.0.2\Server\tomcat-5.0.24\conf
The uriworkermap.properties is a simple text file that determines the kind of requests that get passed on to Tomcat rather than being handled by IIS. This is my example setup of the uriworkermap.properties file. I set it to handle everything with the url /lps-4.0.2, specifying * rather than *.lzx because I didn't want to have to add a line for every single file extension in Laszlo's directory.
If you wanted just .lzx files handled for instance you could just specify:
Where you put your Laszlo code
Laszlo code should stay in the normal Laszlo area, for me it is C:\Program Files\OpenLaszlo Server 4.0.2\Server\lps-4.0.2
So a call to a sample page might be http://localhost/lps-4.0.2/my-apps/test_app/bin/testapp.lzx
But it could also be simply http://localhost/lps-4.0.2/test.lzx if you have a single file in the root directory.
It might be possible to store Laszlo files within the main webroot, modifying the uri properties file. That isn't tested though.
If you wish to upgrade your version of Laszlo and have already done the above described setup, it is still fairly easy.
Whilst the existing Laszlo is still running
- install the new version of Laszlo alongside
- copy the configuration files in the tomcat conf directory, except for server.xml - I'd recommend manually changing it again as it may have a different format.
- you can test the new setup on a different port by changing server.xml
- update the new configuration files to the new paths
Whilst the existing Laszlo is stopped
- update your virtual directory in IIS
- update your registry settings
- restart the IIS service if necessary
Troubleshooting and Ongoing Debugging
For development and troubleshooting I run Tomcat off the commandline in a window, rather than as a service. The jk_iis.log log file still tells you more than the window though. IIS by default won't give you enough information in its logs so you'll need to ramp up what it tells you.
You can increase the logging in the jk_iis.log file by changing 'info' to 'debug' for the log level. You will need to restart the service to enact the change.
Increasing IIS logging
These steps are for increasing the level of IIS logging so that you can see GET/POST request details coming from Laszlo. Obviously this is for a development machine rather than a live server and a normal ISP won't be making these changes for you.
- as an admin open the IIS console
- open the properties of the website where Laszlo runs
- enable logging if not already enabled
- set it to use W3C Extended Log File Format
- click on the 'Properties' button in the logging area
- note where it saves the log file for your reference
- go to the extended properties tab
- enable extended properties and consider enabling Client IP address, URI stem, URI query, Method (this is POST or GET), bytes sent, bytes received, time taken etc.
- Make sure the user IIS runs as has permission to see the Laszlo web tree and to write to the log file (you specify the path in the registry settings mentioned above)
- Make sure the port for the worker in your properties file and the connector in the server.xml are the same. If they are different or the connector isn't in place in server.xml, you'll see Tomcat make the request but time out with no response
- Make sure that if you're using sessions authentication, a session is actually active in your browser. Laszlo might be expecting an xml response from the server but instead is actually getting an HTML login page (HTML 4 isn't well-formed so it will generate errors)
- Paste links or requests in the browser manually to check that you have the right url/uri. Laszlo might be getting a 404 'page not found' or being redirected to a default page (the IIS log will show that too).
- Make sure the uriworker.properties file is setup to handle the requests - it has to be clear which requests will be handled by IIS and which will be handled by Tomcat.
- if something is wrong here, you will see IIS display the contents of the .lzx file instead of executing it
- if your Laszlo page doesn't appear or appears broken in development mode (where it displays compile buttons and the like), remember that the uriworker.properties file either has to have * for all extensions or a line for each extension Tomcat handles eg. *.js *.lzx *.swf *.htm, not just *.lzx, because it uses a page that embeds the Flash. Look in the /lps directory in the Laszlo web tree and see which file extensions are used.
- Restarting IIS or even the whole machine might help after you set it up for the first time
- If Tomcat says that it's discarding an unexpected response '100 continue', that message can usually be ignored and the show can go on