How to configure tomcat java web application in Apache?

November 25, 2016 109 views
Java Apache Ubuntu

Hi,

I have a tomcat web application which is running under http://localhost:8080/app_name.

Now i would like to configure that application under apache, for that i created one config file under sites-available/ and i enabled that site.config using a2ensite. Now i have config shortcut under sites-enable/.

configured host:

<VirtualHost *:80>
ServerName domain.com
ProxyRequests Off
ProxyPreserveHost On
<Proxy *>
Order deny,allow
Allow from all
</Proxy>
ProxyPass / http://localhost:8080/realmilk/app_name
ProxyPassReverse / http://localhost:8080/app_name
</VirtualHost>

When i run that configured domain i got

<^>Internal Server Error

The server encountered an internal error or misconfiguration and was unable to complete your request.

Please contact the server administrator at [no address given] to inform them of the time this error occurred, and the actions you performed just before this error.

More information about this error may be available in the server error log.

Apache/2.4.7 (Ubuntu) Server at adavipalem.com Port 80<^>

Thanks & Regards

2 Answers

Did you enabled ProxyPass module?

If not:

  • sudo a2enmod proxy

This requires you to restart Apache:

  • sudo systemctl restart apache2
  • When i run sudo systemctl restart apache2 it 'll says like

    sudo systemctl restart apache2
    

    Regards,

    • I think you copied command again, instead of output

      • Hi,
        I'm really sorry for that and thank you for your best concern.

        sudo: systemctl: command not found
        
        • Go on with:

          • sudo service apache2 restart

          If you're using Ubuntu 14.04, systemctl is not a available so you need to use service.

        • Make sure you specified correct app URL for ProxyPass and that app is running.

          ProxyPass / http://localhost:8080/realmilk/app_name
          ProxyPassReverse / http://localhost:8080/app_name
          

          Look at this, make sure you entered right URLs there.

          Logs would probably give you more insight. You can look at /var/log/apache2/error.log (with text editor).

          • I updated the config like this...

            <VirtualHost *:80>
                ServerName domain.com
                ProxyRequests Off
                ProxyPreserveHost On
                <Proxy *>
                    Order deny,allow
                    Allow from all
                </Proxy>
                ProxyPass / http://localhost:8080/app_name
                ProxyPassReverse / http://localhost:8080/app_name
            </VirtualHost> 
            

            and i restarted the apache2 service.. but again 500 Internal Server Error

            Regards

When integrating with Tomcat, this guide recommends using JKMount /* ajp13_worker which allows Tomcat to integrate more closely with apache.

Apache Tomcat is a web server and servlet container designed to serve Java applications. Frequently used in production enterprise deployments and for smaller application needs, Tomcat is both flexible and powerful. In this guide, we will discuss how to secure your Ubuntu...
Have another answer? Share your knowledge.