<s1 title="Resin with Apache on Windows">

<p>Resin provides a fast servlet runner for Apache, allowing Apache
to run servlets and JSP files.</p>

<figure src='apache_srun.gif'/>

<summarylist/>

<s2 title='Configuring Apache'>

<p>To configure Apache to load the Caucho Server Runner, add the
following lines to the Apache httpd.conf file:</p>

<example title=httpd.conf>
LoadModule caucho_module &lt;installdir>/resin-2.1.0/libexec/apache-1.3/mod_caucho.dll
# Note, AddModule not needed for Apache 2.0
AddModule mod_caucho.c

&lt;IfModule mod_caucho.c&gt;
  CauchoConfigFile &lt;installdir>/resin-2.1.0/resin.conf
  &lt;Location /caucho-status>
    SetHandler caucho-status
  &lt;/Location>
&lt;/IfModule&gt;
</example>

<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.</note>

<s3 title='Alternate Apache Configuration'>

<p>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 ensure the Apache configuration matches the Resin configuration.</p>

<example title=httpd.conf>
LoadModule caucho_module &lt;installdir>/resin-2.1.0/libexec/apache-1.3/mod_caucho.dll
AddModule mod_caucho.c

CauchoHost localhost 6802
AddHandler caucho-request jsp
&lt;Location /servlet/*>
   SetHandler caucho-request
&lt;/Location>
</example>

<deftable>
<tr><th>Apache Command<th>Meaning
<tr><td>CauchoConfigFile <var/conf/><td>Reads <var/conf/> for the Resin configuration.
<tr><td>CauchoServerRoot <var/directory/><td>Configures the equivalent of -server-root.
<tr><td>CauchoHost <var/host/> <var/port/><td>Adds the Resin JVM at <var/host:port/> as a servlet runner.
<tr><td>CauchoBackup <var/host/> <var/port/><td>Adds the Resin JVM at <var/host:port/> as a backup servlet runner.
<tr><td>
</deftable>

</s3>

<s3 title="Dispatching">

<p>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 <a
href="../java_tut/plugin-dispatch.xtp">plugin-dispatch</a> tutorial.</p>

</s3>
</s2>
<s2 title='Load Balancing' version='Resin 1.2'>

<p>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.</p>

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

<p>See the <a href='http-config.xtp'>http config</a> section for more
details.</p>

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

<s2 title='Error Page' version='Resin 1.2'>

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

<example title=resin.conf>
...
&lt;web-app>
  &lt;error-page exception-type='connection'
              location='/conn_error_page.html'/>
  ...
&lt;/web-app>
</example>

</s2>

<s2 title='Configuring resin.conf'>

<p>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 <var/app-dir/>.
Change <var/app-dir/> from 'doc' to something like '/usr/local/apache/htdocs'.
</p>

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

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

</s2>

<s2 title='Testing the servlet engine'>

<p>Now you need to start the servlet engine.  From the resin-2.1.0/bin
folder, click on srun.</p>

<example>
> resin-2.0/bin/httpd
</example>

<p>Now browse http://localhost/test.jsp.  You should get a 'file not
found' message.<p/>

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

<example>
2 + 2 = &lt;%= 2 + 2 %>
</example>

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

<results>
2 + 2 = 4
</results>

</s2>

<s2 title='Deploying on NT'>

<p>The Servlet Runner can be installed as an NT service.</p>

<p>To install the service, use</p>

<example>
unix> resin-2.1.0/bin/httpd -install
</example>

<p>To remove the service, use</p>

<example>
unix> resin-2.1.0/bin/httpd -remove
</example>

<p>You will either need to reboot the machine or start the service
from the Control&nbsp;Panel/Services panel to start the server.  On a
machine reboot, NT will automatically start the servlet runner.</p>

</s2>
</s1>
