Hyrax - Apache Integration: Difference between revisions
No edit summary |
No edit summary |
||
Line 11: | Line 11: | ||
You have to create the AJP connector in the ''conf/server.xml'' file: | You have to create the AJP connector in the ''conf/server.xml'' file: | ||
<source lang="xml"> | |||
<Connector port="8009" enableLookups="false" redirectPort="8443" protocol="AJP/1.3" /> | <Connector port="8009" enableLookups="false" redirectPort="8443" protocol="AJP/1.3" /> | ||
</source> | |||
This line will enable AJP connections to the 8009 port of your tomcat server (localhost for example). | This line will enable AJP connections to the 8009 port of your tomcat server (localhost for example). | ||
Line 19: | Line 21: | ||
Add this to Apache's ''httpd.conf'' file: | Add this to Apache's ''httpd.conf'' file: | ||
<source lang="apache"> | |||
<source lang=" | |||
<Proxy *> | <Proxy *> | ||
AddDefaultCharset Off | AddDefaultCharset Off | ||
Line 30: | Line 31: | ||
ProxyPassReverse / ajp://localhost:8009/ | ProxyPassReverse / ajp://localhost:8009/ | ||
</source> | </source> | ||
NB: It's possible to embed these in a ''VirtualHost'' directive. | NB: It's possible to embed these in a ''VirtualHost'' directive. | ||
Line 58: | Line 58: | ||
You will need to add (something like) the following to your Apache web server's httpd.conf file: | You will need to add (something like) the following to your Apache web server's httpd.conf file: | ||
<source lang="apache"> | |||
<source lang=" | |||
# | # | ||
# Compress everything except images. | # Compress everything except images. | ||
Line 90: | Line 89: | ||
</source> | </source> | ||
</font> | </font> | ||
== Authentication == | |||
In many cases Hyrax may deployed into service stacks in which ''httpd'' is expected to handle the work of authenticating users. In order for Tomcat (and thus Hyrax) to be able to access receive the users login "profile" from ''httpd'' the following things need to be done. | |||
=== Tomcat === | |||
In the ''$CATALINA_HOME/conf/server.xml'' file the default definition of the AJP connector typically looks like: | |||
<source lang="xml" > | |||
<!-- Define an AJP 1.3 Connector on port 8009 --> | |||
<Connector port="8009" protocol="AJP/1.3" redirectPort="8443" /> | |||
</source> |
Revision as of 15:45, 24 October 2014
Overview
The problem of linking Tomcat with Apache has been greatly reduced as of Apache 2.2. In previous incarnations of Apache & Tomcat, it was fairly complex. To see how to solve the problem for older versions of Apace, see the old Apache Integration instructions. What follows are the instructions for Apache 2.2 and Tomcat 6.x.
Prerequisites
- Apace 2.2 or greater
- Tomcat 6.x or greater
- mod_proxy_ajp installed in Apache (typically this is present in 2.2+)
Connecting Tomcat to Apache
Tomcat
You have to create the AJP connector in the conf/server.xml file:
<Connector port="8009" enableLookups="false" redirectPort="8443" protocol="AJP/1.3" />
This line will enable AJP connections to the 8009 port of your tomcat server (localhost for example).
Apache
In the example below, pay special attention to the protocol part of the proxy URL - it uses ajp:// and not 'http://'.
Add this to Apache's httpd.conf file:
<Proxy *>
AddDefaultCharset Off
Order deny,allow
Allow from all
</Proxy>
ProxyPass / ajp://localhost:8009/
ProxyPassReverse / ajp://localhost:8009/
NB: It's possible to embed these in a VirtualHost directive.
How It Works
ProxyPass and ProxyPassReverse are classic reverse proxy directives used to forward the stream to another location. ajp://... is the AJP connector location (your tomcat's server host/port)
A web client will connect through HTTP to http://localhost/ (supposing your apache2 server is running on localhost), the mod_proxy_ajp will forward you request transparently using the AJP protocol to the tomcat application server on localhost:8009.
Apache Compressed Responses
Many OPeNDAP clients accept compressed responses. This can greatly increase the efficiency of the client/server interaction by diminishing the number of bytes actually transmitted over "the wire". Compression can reduce the number of bytes transmitted by an order of magnitude for many datasets!
Tomcat provides native compression support for the GZIP compression mechanism, however it is NOT turned on by default. More perversely, even if you have configured Tomcat to provide compressed responses, if you are using AJP to proxy Tomcat through the Apache web server compression will not be enabled unless you configure the Apache web server to compress responses. This is because Tomcat NEVER compresses responses sent over AJP.
When you configure your Apache web server to provide compressed responses you will probably want to make sure that Apache doesn't apply compression to images (In general images are already compressed and there is little to gain by attempting to compress them and a lot of CPU cycles to burn if you try)
BetterExplained explains Apache Compression
httpd.conf
You will need to add (something like) the following to your Apache web server's httpd.conf file:
#
# Compress everything except images.
#
<Location />
# Insert filter
SetOutputFilter DEFLATE
# Netscape 4.x has some problems...
BrowserMatch ^Mozilla/4 gzip-only-text/html
# Netscape 4.06-4.08 have some more problems
BrowserMatch ^Mozilla/4\.0[678] no-gzip
# MSIE masquerades as Netscape, but it is fine
# BrowserMatch \bMSIE !no-gzip !gzip-only-text/html
# NOTE: Due to a bug in mod_setenvif up to Apache 2.0.48
# the above regex won't work. You can use the following
# workaround to get the desired effect:
BrowserMatch \bMSI[E] !no-gzip !gzip-only-text/html
# Don't compress images
SetEnvIfNoCase Request_URI \
\.(?:gif|jpe?g|png)$ no-gzip dont-vary
# Make sure proxies don't deliver the wrong content
Header append Vary User-Agent env=!dont-vary
</Location>
Authentication
In many cases Hyrax may deployed into service stacks in which httpd is expected to handle the work of authenticating users. In order for Tomcat (and thus Hyrax) to be able to access receive the users login "profile" from httpd the following things need to be done.
Tomcat
In the $CATALINA_HOME/conf/server.xml file the default definition of the AJP connector typically looks like:
<!-- Define an AJP 1.3 Connector on port 8009 -->
<Connector port="8009" protocol="AJP/1.3" redirectPort="8443" />