caucho
Resin
FAQ
Reference Guide
Demo
Tutorial

Getting Started
Configuration
IDE
Topics
JSP
XML/XSLT

Resin Web Server
Unix Apache
Windows Apache
Unix Netscape
IIS
WebSite
 Resin with Apache on Unix

Resin Web Server
Getting Started
Windows Apache

  1. Installation
    1. Compiling Apache
    2. Compiling mod_caucho.so
    3. Configure the Environment
    4. Configuring resin.conf
    5. Starting the Servlet Engine
    6. Testing the servlet engine
  2. Configuring Apache by hand
    1. Virtual Hosts
    2. Dispatching
  3. Load Balancing
  4. Error Page
  5. Troubleshooting

Resin provides a fast servlet runner for Apache, allowing Apache to run servlets and JSP files. The servlet runner needs Apache 1.3.x and DSO support.

Installation

To configure Resin with Apache, you must follow the following steps:

  1. Compiling Apache
  2. Compile mod_caucho.so
  3. Configure Apache
  4. Set up environment
  5. Configure resin.conf
  6. Restart Apache and start srun

Compiling Apache

You need a version of Apache with DSO support enabled. Apache has full documentation at http://httpd.apache.org/docs/dso.html.

Many distributions, e.g. Red Hat Linux, will have Apache preinstalled. However, because the standard distribution has files all over the place, some people prefer to recompile Apache from scratch.

Once you untar Apache, build it like:

unix> ./configure --prefix=/usr/local/apache \
  --enable-module=so
unix> make
unix> make install

Solaris versions of Apache may need additional flags, otherwise you'll get some linking errors when trying to load Resin. You may need to refer to the Apache documentation if you get linking errors. Here's an example configuration on Solaris:

unix> ./configure --prefix=/usr/local/apache \
                  --enable-rule=SHARED_CORE \
                  --enable-rule=SHARED_CHAIN \
                  --enable-module=so \
                  --enable-module=most \
                  --enable-shared=max

Compiling mod_caucho.so

To compile and install mod_caucho on Unix, you'll need to run Resin's configure and then make. This step will create mod_caucho.so and put it in the Apache module directory. Usually, mod_caucho.so will end up in /usr/local/apache/libexec/mod_caucho.so.

If you know where your apxs executable is, you can use --with-apxs. apxs is a little Perl script that the Apache configuration makes. It lets modules like Resin know how all the Apache directories are configured. It is generally in /usr/local/apache/bin/apxs or /usr/sbin/apxs. It's usually easiest to use --with-apxs so you don't need to worry where all the Apache directories are.

unix> ./configure --with-apxs=/usr/local/apache/bin/apxs
unix> make
unix> make install

Even if you don't know where apxs is, the configure script can often find it:

unix> ./configure --with-apxs
unix> make
unix> make install

As an alternative to --with-apxs, if you've compiled Apache yourself, or if you have a simple configuration, you can generally just point to the Apache directory:

unix> ./configure --with-apache=/usr/local/apache
unix> make
unix> make install

The previous --with-apxs or --with-apache should cover most configurations. For some unusual configurations, you can have finer control over each directory with the following arguments to ./configure. In general, you should use --with-apache or --with-apxs, but the other variables are there if you know what you're doing.

--with-apache=dirThe Apache root directory.
--with-apxs=apxsPointer to the Apache extension script
--with-apache-include=dirThe Apache include directory
--with-apache-libexec=dirThe Apache module directory
--with-apache-conf=httpd.confThe Apache config file

Configure the Environment

If you don't already have Java installed, you'll need to download a JDK and set some environment variables.

Here's a typical environment that you might put in ~/.profile or /etc/profile

# Java Location
JAVA_HOME=/<installdir>/jdk1.2.2
export JAVA_HOME

# Resin location (optional).  Usually Resin can figure this out.
RESIN_HOME=/<installdir>/resin1.2
export RESIN_HOME

# If you're using additional class libraries, you'll need to put them
# in the classpath.
CLASSPATH=

Configuring resin.conf

By default, Resin will look in resin-2.1.0/doc for JSP files and resin-2.1.0/doc/WEB-INF/classes for servlets and beans. To tell Resin to use Apache's document area, you configure the app-dir. Change app-dir from 'doc' to something like '/usr/local/apache/htdocs'.

resin.conf
<caucho.com>
  <http-server
      app-dir='/usr/local/apache/htdocs'>
    <servlet-mapping url-pattern='/servlets/*'
              servlet-name='invoker'/>

    <servlet-mapping url-pattern='*.xtp'
                        servlet-name='com.caucho.jsp.XtpServlet'/>
    <servlet-mapping url-pattern='*.jsp'
                        servlet-name='com.caucho.jsp.JspServlet'/>
  </http-server>
</caucho.com>

Starting the Servlet Engine

Now you need to start the servlet engine. Starting Resin is the same with Apache or standalone. See the httpd page for a detailed description.

unix> resin1.2/bin/httpd.sh
Resin 1.2.s010113 -- Sat Jan 13 11:17:18 PST 2001
http listening to *:8080
srun listening to localhost:6802

Resin will print every port it's listening to. In the above example, Resin is listening to port 8080 using HTTP and 6802 using its servlet runner protocol. In other words, mod_caucho can connect to Resin with 6802 only on same host, but you can browse port 8080 from any host.

The following snippet shows the <http> and <srun> configuration for the above example.

<caucho.com>
  <http-server>
    <http port='8080'/>
    <srun host='localhost' port='6802'/>

    ...
  </http-server>
</caucho.com>

Testing the servlet engine

Create a test file '/usr/local/apache/htdocs/test.jsp'

2 + 2 = <%= 2 + 2 %>

Browse http://localhost/test.jsp again. You should now get

2 + 2 = 4

Configuring Apache by hand

Making mod_caucho will automatically change your httpd.conf file. You can also configure Apache directly, instead of letting mod_caucho read the configuration from the resin.conf file. If you use this method, you need to make sure you match the Apache configuration with the Resin configuration.

httpd.conf
LoadModule caucho_module libexec/mod_caucho.so
AddModule mod_caucho.c

<IfModule mod_caucho.c>
  CauchoConfigFile <installdir>/resin1.2/conf/resin.conf
  <Location /caucho-status>
    SetHandler caucho-status
  </Location>
</IfModule>

Note: The caucho-status is optional and probably should be avoided in a production site. It lets you ask the Caucho Apache module about the Caucho status, valuable for debugging.

Restart Apache. Now browse http://localhost/caucho-status. It should return a table indicating that the servlet runner is stopped.

Browse http://localhost/test.jsp. It should return a message like:

Cannot connect to Servlet Runner.

You can also dispatch to Resin directly from the httpd.conf. The apache handler name is "caucho-request".

Apache HandlerMeaning
caucho-statusHandler to display /caucho-status
caucho-requestDispatch a request to Resin

Requests dispatched directly from the Apache httpd.conf will not appear in /caucho-status. You can use caucho-request as follows:

<Location /foo/*>
  SetHandler caucho-request
</Location>

Apache CommandMeaning
CauchoConfigFile confReads conf for the Resin configuration.
CauchoServerRoot directoryConfigures the equivalent of -server-root.
CauchoHost host portAdds the Resin JVM at host:port as a servlet runner.
CauchoBackup host portAdds the Resin JVM at host:port as a backup servlet runner.

Virtual Hosts

The virtual host topic describes virtual hosts in detail. If you're using a single JVM, you only need to configure the resin.conf. If you want a different JVM for each virtual host, your httpd.conf can load a different resin.conf for each JVM:

httpd.conf
<VirtualHost foo.com>
ServerName foo.com
ServerAlias www.foo.com
CauchoConfigFile /home/foo/conf/foo.conf
</VirtualHost>

<VirtualHost bar.com>
ServerName bar.com
ServerAlias www.bar.com
CauchoConfigFile /home/bar/conf/bar.conf
</VirtualHost>

The foo.conf might look something like:

foo.conf
<caucho.com>
<http-server>
  <srun host='foo.com' port='6802'/>

  <host id='www.foo.com'>
     ...
  </host>
</caucho.com>

Dispatching

mod_caucho selects URLs specified by the servlet-mapping directives to go to Resin. Other URLs stay with Apache. There's a more complete discussion of the URL dispatching in the plugin-dispatch tutorial.

Load BalancingResin 1.2

In Resin 1.2, you can distribute requests to multiple machines. All requests in a session will go to the same host. In addition, if one host goes down, Resin will send the request to the next available machine.

In addition, you can specify backup machines. The backup only will serve requests if all primaries are down.

See the http config section for more details.

resin.conf
<caucho.com>
<http-server>
  <srun id="a" host='host1' port='6802'/>
  <srun id="b" host='host2' port='6802'/>
  <srun-backup id="c" host='backup port='6802'/>
  ...
</http-server>
</caucho.com>

Error PageResin 1.2

When mod_caucho can't reach any JVM, it will send a default error page. Sites can customize the error page with the error-page directive in the resin.conf.

resin.conf
...
<web-app>
  <error-page exception-type='connection'
              location='/conn_error_page.html'/>
  ...
</web-app>

Troubleshooting

  1. First, check your configuration with the standalone httpd.sh. In other words, add a <http port='8080'/> and check port 8080.
  2. Check http://localhost/caucho-status. That will tell if mod_caucho has properly read the resin.conf.
  3. Each srun host should be green and the mappings should match your resin.conf.
  4. If caucho-status fails entirely, the problem is in the mod_caucho installation and the Apache httpd.conf.
  5. If caucho-status shows the wrong mappings, there's something wrong with the resin.conf or the pointer to resin.conf in httpd.conf.
  6. If caucho-status shows a red servlet runner, then httpd.sh hasn't properly started.
  7. If you get a "cannot connect to servlet engine", caucho-status will show red, and httpd.sh hasn't started properly.
  8. If httpd.sh doesn't start properly, you should look at the logs in resin1.2/log. You should start httpd.sh -verbose to get more information.
  9. If httpd.sh says "no servers defined", your resin.conf is missing a <srun> or <httpd> definition.
  10. If httpd.sh never shows a "srun listening to *:6802" line, it's not paying attention to mod_caucho. You'll need to add a <srun> line.
  11. If httpd.sh shows "srun listening to localhost:6802" line, only an Apache on the same host can connect to the srun. If you need an Apache on a different host to connect to srun, you'll need to change the host attribute in the srun configuration.
  12. If you get Resin's "file not found", the Apache configuration is good but the resin.conf probably points to the wrong directories.

Resin Web Server
Getting Started
Windows Apache
Copyright © 1998-2002 Caucho Technology, Inc. All rights reserved.
Resin® is a registered trademark, and HardCoretm and Quercustm are trademarks of Caucho Technology, Inc.