Apache as Frontend
Apache as the Frontend of Tomcat
Placing Apache in front of Tomcat can provide URL rewriting, static-content delivery, load balancing, additional security controls, and access to Apache modules while Tomcat continues to run the Java applications.
Overview
Apache can forward client requests to one or more Tomcat application servers through mod_proxy or mod_rewrite, then relay the Tomcat responses back to the user.
Rewriting Application Links
The documented example uses two applications hosted in separate Tomcat environments:
https://env-tomcat.jelastic.com/app1/https://second-tomcat.jelastic.com/app2/

Prepare the environments
Create one Apache frontend environment and two or more backend Tomcat environments with the Java applications deployed.
Edit Apache configuration
Click Config beside Apache and open /etc/httpd/conf/httpd.conf. Add the routing rules inside the VirtualHost block.
<VirtualHost *:80> ServerAdmin webmaster@domain.com DocumentRoot /var/www/webroot/ROOT ServerName website.jelastic.com RewriteEngine On RewriteRule ^/application1/(.*) http://env-tomcat.jelastic.com/app1/ [P] ProxyPassReverse /application1/ http://env-tomcat.jelastic.com/app1/ RewriteRule ^/application2/(.*) http://second-tomcat.jelastic.com/app2/ [P] ProxyPassReverse /application2/ http://second-tomcat.jelastic.com/app2/ RewriteLog "/var/log/httpd/rewrite.log" ErrorLog logs/dummy-host.jelastic.com-error_log CustomLog logs/dummy-host.jelastic.com-access_log common </VirtualHost>

Directive purpose
RewriteEngine On enables rewriting. RewriteRule and ProxyPassReverse define the forwarding rules. RewriteLog is optional and records rewrite activity.
Save, restart, and test
Save the file, restart Apache, and open the frontend URL with /application1/ or /application2/.
Serving Static Content
Apache can deliver static files while all other requests are proxied to Tomcat.

Create the static folder
Open Apache Configuration Manager, go to /var/www/webroot/ROOT, create a folder such as static, and upload the static files.
Configure proxy exclusions
Open /etc/httpd/conf/httpd.conf and configure the frontend so requests for the static folder stay on Apache while all other requests go to Tomcat.
<VirtualHost *:80> ServerAdmin webmaster@domain.com DocumentRoot /var/www/webroot/ROOT ServerName website.jelastic.com ServerAlias * ProxyPass /static ! ProxyPass / http://env-tomcat.jelastic.com/app1/ ProxyPassReverse / http://env-tomcat.jelastic.com/app1/ ErrorLog logs/dummy-host.jelastic.com-error_log CustomLog logs/dummy-host.jelastic.com-access_log common </VirtualHost>
Proxy exclusion
ProxyPass /static ! prevents requests beginning with /static from being proxied. All other requests are forwarded to Tomcat.
Restart and verify
Restart Apache. Open the frontend URL to verify the proxied Tomcat application, then open /static/ to verify the static content.
Load Balancing
The documented load-balancing example uses one Apache frontend and two Tomcat backend environments. Both Tomcat applications must be deployed under the same context.

Create the backend host list
In /etc/httpd/conf.d, create a file named servers_list and add the backend hosts:
servers {env1_name}.{hoster_domain}|{env2_name}.{hoster_domain}
Add the balancing rules
Open /etc/httpd/conf/httpd.conf and configure a random rewrite map.
<VirtualHost *:80>
ServerAdmin webmaster@domain.com
DocumentRoot /var/www/webroot/ROOT
ServerName website.jelastic.com
ServerAlias *
RewriteEngine On
RewriteMap lb rnd:/etc/httpd/conf.d/servers_list
RewriteRule ^/(.*) http://${lb:servers}/app1/$1 [P,L]
RewriteLog "/var/log/httpd/rewrite.log"
ErrorLog logs/dummy-host.jelastic.com-error_log
CustomLog logs/dummy-host.jelastic.com-access_log common
</VirtualHost>
How it works
RewriteMap points to the backend-host list, and RewriteRule forwards incoming requests to a randomly selected Tomcat server.
Restart and test distribution
Restart Apache and open the frontend URL. Refresh the page several times to confirm that requests are being sent to different Tomcat servers.
Expected Result
Apache operates as the public frontend while Tomcat runs the Java applications. The frontend can expose several applications through descriptive paths, serve static files directly, or distribute requests between multiple Tomcat backends.
Important Notes
- Back up
httpd.confbefore editing it. - Restart Apache after saving configuration changes.
- Use identical application contexts on the Tomcat backends used for load balancing.
- Protect backend Tomcat environments from unnecessary public access.
- The source page uses historical Apache rewrite directives; validate them against the Apache version running in your environment.
- Review Apache rewrite, access, and error logs during troubleshooting.
Common Issues and Solutions
ProxyPass /static ! exclusion before the general proxy rule.