Apache + Tomcat
From Oxxus Wiki
Apache web server, with proxy_ajp module, is installed by default within every VPS hosting plan we offer. It's required because Tomcat services are set, again by default, to port 8080 and all incoming requests from standard web port 80 which are related to java contents, are forwarded by this module to Tomcat server, at port 8080.
Configurations regarding this module are quite simple and map all requests from port 80 to 8080. Exclusion can be defined as well but only for entire folder and its sub-folders. Mapping per file extension, for example, if you need to have PHP and Java contents served from same folder, is not possible. If this is what you require, we offer mod_jk, another Apache module, which has this feature enabled. Although mod_jk requires more configuration, it provides, on the other hand, more sophisticated configuration options.
proxy_ajp configuration example
There is just one configuration file required to have this module active and redirect java requests to Tomcat , named java.conf, at our VPS accounts, with contents as shown below. File is placed at Apache's configuration folder so Apache can pick it up upon start-up.
ProxyPass /webmail ! ProxyPass /phpMyAdmin ! ProxyPass /phpPgAdmin ! ProxyPass /cgi-bin ! ProxyPass /server-status ! ProxyPass / http://127.0.0.1:8080/ ProxyPassReverse / http://127.0.0.1:8080/ ProxyPreserveHost on
We've predefined some exclusions, as shown above, which lets Apache to handle contents.
mod_jk configuration example
Several configuration files are required for this module to work, however the module provides far more detailed configuration features than proxy_ajp. Main and most used is ability to define redirection to Tomcat service per file extensions, as shown below in our example.
Like proxy_ajp, all configuration files have to be placed within Apache's configuration folder so they can be picked up once Apache started.
First file is named mod_jk.conf
LoadModule jk_module modules/mod_jk.so JkWorkersFile /etc/httpd/conf/workers.properties JkLogFile /var/log/httpd/mod_jk.log JkLogLevel info JkLogStampFormat "[%a %b %d %H:%M:%S %Y] "
It invokes file workers.properties
worker.ajp13.port=8009 worker.ajp13.host=localhost worker.ajp13.type=ajp13
Now, mod_jk is enabled, but definition of what to be mounted is also required. It can be done from one of previous files or within Apache configuration file.
JkMount /* ajp13 JkMount /servlet/* ajp13 JkUnMount /*.php ajp13 JkUnMount /*/*.php ajp13 JkUnMount /*/.shtml ajp13 JkUnMount /.shtml ajp13 JkUnMount /admin/* ajp13 JkUnMount /webmail/* ajp13
As defined above, everything is mounted to java services, Tomcat in this case, and then certain files extensions, like PHP are left unmounted. Entire folders can be mounted or unmounted as well. With this configuration, your web site will be able to serve Apache/PHP and java contents at the same time from same folder, for entire web site.