I have a domain that is hosted on an unmanaged VPS server with Ubuntu 16.04 I have configured my Java EE Tomcat web app to be served up at my domain name. But the response times for the app are way too slow, progressively going toward timeouts in the browser. If I stop the apache2 service and access my web app through domain:8080 the web app performance is perfect. How do you correctly configure apache2 to serve up the tomcat web app at the domain name with good performance? I realize that the easy solution is to link all references to my web app to domain:8080, but I would like to know how to correctly configure apache2 to serve up the Tomcat web app at the domain with the same performance as using domain:8080. Thanks in advance for any help.

This is my apache2 sites-available file for the domain:

<VirtualHost *:80>

  # Admin email, Server Name (domain name) and any aliases
  ServerAdmin webmaster@lae-laeweb.com
  ServerName  lae-laeweb.com
  ServerAlias www.lae-laeweb.com

  # Index file and Document Root (where the public files are located)
  DirectoryIndex index.html
  DocumentRoot /var/www/html

  # Custom log file locations
  LogLevel warn
  ErrorLog /var/log/apache2/error-lae-laeweb.com.log
  CustomLog /var/log/apache2/access-lae-laeweb.com.log combined

    #ServerName www.lae-laeweb.com

     ProxyRequests On
     ProxyPass / http://lae-laeweb.com:8080/LAEWeb/ keepalive=on ttl=60
     ProxyPassReverse / http://lae-laeweb.com:8080/LAEWeb/

    <Location />
        Order allow,deny
        Allow from all


This is a script I use after uploading a new .war file for my web app to tomcat:


cd ../usr/local/apache-tomcat-8.5.23/bin



cd ../../../..

service apache2 reload

service apache2 restart


if (( $(ps -ef | grep -v grep | grep $service | wc -l) > 0 ))
echo "$service is running!!!"
/etc/init.d/$service restart

server.xml for tomcat:

<?xml version="1.0" encoding="UTF-8"?>

<Server port="8005" shutdown="SHUTDOWN">
  <Listener className="org.apache.catalina.startup.VersionLoggerListener" />

  <Listener className="org.apache.catalina.core.AprLifecycleListener" SSLEngine="on" />
  <Listener className="org.apache.catalina.core.JreMemoryLeakPreventionListener" />
  <Listener className="org.apache.catalina.mbeans.GlobalResourcesLifecycleListener" />
  <Listener className="org.apache.catalina.core.ThreadLocalLeakPreventionListener" />


    <Resource name="UserDatabase" auth="Container"
              description="User database that can be updated and saved"
              pathname="conf/tomcat-users.xml" />

   <Service name="Catalina">

     <Connector port="8080" protocol="HTTP/1.1"
           maxThreads="200" acceptCount="100" />

    <!-- Define an AJP 1.3 Connector on port 8009 -->
    <Connector port="8009" protocol="AJP/1.3" redirectPort="8443" connectionTimeout="60000" />

    <Engine name="Catalina" defaultHost="lae-laeweb.com:8080">

      <Realm className="org.apache.catalina.realm.LockOutRealm">

        <Realm className="org.apache.catalina.realm.UserDatabaseRealm"

<Host name="lae-laeweb.com" appBase="webapps" unpackWARs="true" autoDeploy="true">
      <Context path="" docBase="/usr/local/apache-tomcat-8.5.23/webapps/LAEWeb" debug="0" privileged="true" reloadable="true" />
      <Valve className="org.apache.catalina.valves.AccessLogValve"
             directory="logs"   prefix="localhost_access_log." suffix=".txt"
             pattern="%h %l %u %t &quot;%r&quot; %s %b" resolveHosts="false" />


When using apache as a proxy that is subject to network delays you should tune buffering to improve performance. As available on the documentation, try adding this to your virtualhost file:

<VirtualHost *:80>


     ProxyRequests On
     ProxyReceiveBufferSize 512
     ProxyPass / http://lae-laeweb.com:8080/LAEWeb/ keepalive=on ttl=60
     ProxyPassReverse / http://lae-laeweb.com:8080/LAEWeb/


As suggested on the documentation, avoid values lower than 512 on the buffer and play around with higher values to see if you end up getting better performance. There's no one size fits all setting here.

  • Thanks I appreciate that. Tried with different values. No help. Just sticking with domain:8080 links for now for production usage. Maybe someone has the answer though. – te7 Oct 15 '17 at 15:51
  • My Tomcat web app uses reflection to dynamically load different classes at different times but not simultaneously. These classes take significant memory. Maybe that's what apache is having trouble with. With accessing Tomcat directly the heap memory is maintained in the app code by deleting unused instances of classes and then doing garbage collection. Maybe also the garbage collection in my code is causing memory issues for apache. – te7 Oct 15 '17 at 18:17
  • But I can initialize tomcat and apache, and the web app at the domain name initially loads fine on the landing page (without calling any classes that use the memory). Then just after 10 or 12 page refreshes of this landing page the browser starts to time out. – te7 Oct 15 '17 at 18:55
  • But if after the landing page I choose options from it that will call the memory using classes the browser begins to time out almost immediately. – te7 Oct 15 '17 at 19:14
  • Can you check server logs on both apache and tomcat? – Zip Oct 15 '17 at 19:39

Found the problem. You have to set "ProxyRequests Off" in domain.conf file in apache2/sites-available folder. Everything working fine now. Thanks to all the posters. Much appreciated.

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.