Apache Http Server Tomcat



This tutorial will help you to setup Apache web server as Reverse Proxy for the Tomcat hosted applications.

Apache Http Server Tomcat

Setup Scenario

Tomcat is running on port 8080 and I have configured two sample applications running with following urls.

Apache server vs tomcat server
  • http://localhost:8080/sample
  • http://localhost:8080/calendar

Tomcat is normally defined as a reference implementation of the Java Servlet and the Java Server Page (JSP) Specifications. It basically executes Java servlets and renders web pages which include JSP coding. It is available on the Apache site in both source and binary versions. While it is entirely possible to have Tomcat serve both your static and dynamic document provision needs, there are several reasons why you might not want want to do this. With respect to the Apache web server, 1. Tomcat is not as fast as Apache when it comes to static pages. Tomcat is not as configurable as Apache. Tomcat has some web server capabilities, however it is not a full blown web server to serve high traffic web sites. In the meantime Apache HTTP server is a full blown web server. So in general Tomcat is configured along with Apache HTTP server to maintain a healthy web site with dynamic content. This tutorial will help you to setup Apache web server as Reverse Proxy for the Tomcat hosted applications. Tomcat is running on port 8080 and I have configured two sample applications running with following urls. There are many ways to compare Tomcat vs. The Apache HTTP Server, but the fundamental difference is that Tomcat provides dynamic content by employing Java-based logic, while the Apache web server's primary purpose is to simply serve up static content such as HTML, images, audio and text.

Now I have installed Apache server on same host running on port 80. I will use Apache server to get users requests and transfer these requests to corresponding applications running on back-end Tomcat server on port 8080. I need to configure Apache to transfer requests to tomcat like below:

  • http://example.com >> http://localhost:8080/demo1/
  • http://example.net >> http://localhost:8080/demo2/
  • http://domain.com/demo1/ >> http://localhost:8080/demo1/
  • http://domain.com/demo2/ >> http://localhost:8080/demo2/

Let’s start the configuration

1. Enable Mod Proxy Apache Module

By default this module is enabled in Apache for users who installed using rpm packages. If you don’t have enabled edit your Apache configuration /etc/httpd/conf/httpd.conf or for Apache 2.4 /etc/httpd/conf.modules.d/00-proxy.conf file and uncomment following lines or put in file.

For the Debian based systems use the following command to enable the Proxy module with Apache. Download puffin for mac.

Apache Http Server Connect Tomcat

2. Configure Apache Virtual Hosts

Now will start working with virtual host. We are creating three virtual hosts as below. You create only which is required with needed modifications. Edit Apache main configuration file and start with the configuration.

VirtualHost Example 1 :-

To forward all requests sent to example.com to backend tomcat server corresponding application like:

  • http://example.com >> http://localhost:8080/demo1/
Apache Http Server Tomcat

Configure virtual host like this.

VirtualHost Example 2 :-

Apache Http Server And Tomcat Together

Cube 2 sauerbraten download mac. To forward all requests sent to example.net to backend tomcat server corresponding application like:

  • http://example.net >> http://localhost:8080/demo2/

Configure virtual host like this.

VirtualHost Example 3 :-

Apache Http Server Tomcat

To forward all requests sent to sub directory /demo1/ or /demo2 on http://domain.com to back-end tomcat corresponding applications like:

  • http://domain.com/demo1/ >> http://localhost:8080/demo1/
  • http://domain.com/demo2/ >> http://localhost:8080/demo2/

Configure virtual host like this.

Apache Http Server Tomcat

3. Restart Apache and Test

After making all necessary changes restart Apache service using the following command and access your sites in a web browser. Make sure you are getting proper pages from tomcat.