Apache Tomcat And Apache Web Server

Posted on  by admin

Besides, Tomcat can function as a Web server on its own with support for servlets and JSP. Despite being surpassed in popularity by NGINX and Apache Web Server, it is still an interesting option to try. That’s why I show you how to install Apache Tomcat on Windows 10/Server. How to stop/start Apache Web Server? You can restart by going to Apache instance location bin. The next step in integrating Apache with Tomcat is to install a web server adapter. This is the piece of software that will relay information between Tomcat and Apache. It doesn't really belong under Apache configuration, and it doesn't really belong under Tomcat configuration, but it's required for both of them to work together. Sample answer: if you will serv only static content and/or php you need Apache web server, if you need java application server/servlet container you need Tomcat. If you will use Tomcat for something more that testing/very light load its wise to put in front Apache web server and use specific plugin for serving requests to Tomcat.

Learn how to use Apache Tomcat server for hosting Java web applications. How to download, install, configure the server and deploy Java web applications into.


Apache Tomcat is a popular, open-source implementation of the Java Servlet and Java Server technologies. This article shows you how to build a container with Apache Tomcat and a simple Web application, deploy the container to a Service Fabric cluster running Linux, and connect to the Web application.

To learn more about Apache Tomcat, see the Apache Tomcat homepage.

Apache Tomcat Web Server Architecture


  • A development computer running:

    • Service Fabric SDK and tools.
    • Docker CE for Linux.
  • A container registry in Azure Container Registry. You can create a container registry in your Azure subscription using the Azure portal or the Azure CLI.

Build a Tomcat image and run it locally

Follow the steps in this section to build a Docker image based on an Apache Tomcat image and a simple Web app and then run it in a container on your local system.

  1. Clone the Service Fabric getting started with Java samples repository on your development computer.

  2. Change directories to the Apache Tomcat server sample directory (service-fabric-java-getting-started/container-apache-tomcat-web-server-sample):

  3. Create a Docker file based on the official Tomcat image located on Docker Hub and the Tomcat server sample. In the service-fabric-java-getting-started/container-apache-tomcat-web-server-sample directory, create a file named Dockerfile (with no file extension). Add the following to Dockerfile and save your changes:

    See the Dockerfile reference for more information.

  4. Login in to Docker and run the docker build command to create the image that runs your web application:

    This command builds the new image using the instructions in the Dockerfile, naming (-t tagging) the image tomcattest. To build a container image, the base image is first downloaded down from Docker Hub and the application is added to it.

    Once the build command completes, run the docker images command to see information on the new image:

  5. Verify that your containerized application runs locally before pushing it the container registry:

    • --name names the container, so you can refer to it using a friendly name rather than its ID.
    • -p specifies the port mapping between the container and the host OS.


    The port you open with the -p parameter should be the port your Tomcat application listens to requests on. In the current example, there is a Connector configured in the ApacheTomcat/conf/server.xml file to listen on port 8080 for HTTP requests. This port is mapped to port 8080 on the host.

    To learn about other parameters, see the Docker run documentation.

  6. To test your container, open a browser and enter one of the following URLs. You will see a variant of the 'Hello World!' welcome screen for each URL.

    • http://localhost:8080/hello
    • http://localhost:8080/hello/sayhello
    • http://localhost:8080/hello/sayhi
  7. Stop the container and delete it from your development computer:

Apache Httpd And Tomcat

Push the Tomcat image to your container registry

Now that you've verified that the Tomcat image runs in a container on your development computer, push it to a repository in a container registry to reduce disruption to your image development and deployment workflows. This article uses Azure Container Registry to store the image, but, with some modification of steps, you can use any container registry you choose. In this article the registry name is assumed to be myregistry and the full registry name is myregistry.azurecr.io. Change these appropriately for your scenario.

  1. Run docker login to sign in to your container registry with your registry credentials.

    The following example passes the ID and password of an Azure Active Directory service principal. For example, you might have assigned a service principal to your registry for an automation scenario. Or, you could sign in using your registry username and password.

  2. The following command creates a tag, or alias, of the image, with a fully qualified path to your registry. This example places the image in the samples namespace to avoid clutter in the root of the registry.

  3. Push the image to your container registry:

Build and deploy the Service Fabric container application

Now that you've pushed the Tomcat image to a container registry, you can build and deploy a Service Fabric container application that pulls the Tomcat image from your registry and runs it as a containerized service in your cluster.

  1. Create a new directory outside of your local clone (outside of the service-fabric-java-getting-started directory tree). Switch to it and use Yeoman to create a scaffold for a container application:

    Enter the following values when prompted:

    • Name your application: ServiceFabricTomcat
    • Name of the application service: TomcatService
    • Input the Image Name: Provide the URL for the container image in your container registry; for example, myregistry.azurecr.io/samples/tomcattest.
    • Commands: Leave this blank. Since this image has a workload entry-point defined, you don't need to explicitly specify input commands (commands run inside the container, which will keep the container running after startup).
    • Number of instances of guest container application: 1
  2. In the service manifest (ServiceFabricTomcat/ServiceFabricTomcat/TomcatServicePkg/ServiceManifest.xml), add the following XML under the root ServiceManfest tag to open the port your application is listening to requests on. The Endpoint tag declares the protocol and port for the endpoint. For this article, the containerized service listens on port 8080:

  1. In the application manifest (ServiceFabricTomcat/ServiceFabricTomcat/ApplicationManifest.xml), under the ServiceManifestImport tag, add the following XML. Replace the AccountName and Password in the RepositoryCredentials tag with the name of your container registry and the password required to sign in to it.

The ContainerHostPolicies tag specifies policies for activating container hosts.

  • The PortBinding tag configures the container port-to-host port mapping policy. The ContainerPort attribute is set to 8080 because the container exposes port 8080, as specified in the Dockerfile. The EndpointRef attribute is set to 'endpointTest', the endpoint defined in the service manifest in the previous step. Thus, incoming requests to the service on port 8080 are mapped to port 8080 on the container.
  • The RepositoryCredentials tag specifies the credentials that the container needs to authenticate with the (private) repository where it pulls the image from. You don't need this policy if the image will be pulled from a public repository.
  1. In the ServiceFabricTomcat folder, connect to your service fabric cluster.
  • To connect to the local Service Fabric cluster, run:

  • To connect to a secure Azure cluster, make sure the client certificate is present as a .pem file in the ServiceFabricTomcat directory, and run:

    In the preceding command, replace your-certificate.pem with the name of your client certificate file. In development and test environments, the cluster certificate is often used as the client certificate. If your certificate is not self-signed, omit the -no-verify parameter.

    Cluster certificates are typically downloaded locally as .pfx files. If you don't already have your certificate in PEM format, you can run the following command to create a .pem file from a .pfx file:

    If your .pfx file is not password protected, use -passin pass: for the last parameter.

  1. Run the install script provided in the template to deploy the application to your cluster. The script copies the application package to the cluster's image store, registers the application type, and creates an instance of the application.

After you have run the install script, open a browser and navigate to Service Fabric Explorer:

  • On a local cluster, use http://localhost:19080/Explorer (replace localhost with the private IP of the VM if using Vagrant on Mac OS X).
  • On a secure Azure cluster, use https://PublicIPorFQDN:19080/Explorer.

Expand the Applications node and note that there is now an entry for your application type, ServiceFabricTomcatType, and another for the first instance of that type. It may take a few minutes for the application to fully deploy, so be patient.

  1. To access the application on the Tomcat server, open a browser window and enter any of the following URLs. If you deployed to the local cluster, use localhost for PublicIPorFQDN. You will see a variant of the 'Hello World!' welcome screen for each URL.

    • http://PublicIPorFQDN:8080/hello
    • http://PublicIPorFQDN:8080/hello/sayhello
    • http://PublicIPorFQDN:8080/hello/sayhi

Clean up

Use the uninstall script provided in the template to delete the application instance from your cluster and unregister the application type.

Apache Tomcat Server Download

After you push the image to the container registry you can delete the local image from your development computer:

Next steps

  • For quick steps on additional Linux container features, read Create your first Service Fabric container application on Linux.
  • For more detailed steps on Linux containers, read the Create a Linux container app tutorial tutorial.
  • Learn more about running containers on Service Fabric.
Learn how web servers and application servers are different, how they’re the same, and how they combine to deliver most of the applications you use today.

Web server vs. application server: What is the difference?

By strict definition, a web server is a common subset of an application server.

A web server delivers static web content—e.g., HTML pages, files, images, video—primarily in response to hypertext transfer protocol (HTTP) requests from a web browser.


An application server typically can deliver web content too, but its primary job is to enable interaction between end-user clients and server-side application code—the code representing what is often called business logic—to generate and deliver dynamic content, such as transaction results, decision support, or real-time analytics. The client for an application server can be the application’s own end-user UI, a web browser, or a mobile app, and the client-server interaction can occur via any number of communication protocols.

In practice, however, the line between web servers and application servers has become fuzzier, particularly as the web browser has emerged as the application client of choice and as user expectations of web applications and web application performance have grown.

Most web servers support plug-ins for scripting languages (e.g., ASP, JSP, PHP, Perl) that enable the web server to generate dynamic content based on server-side logic. And an increasing number of application servers not only incorporate web server capabilities, but use HTTP as their primary protocol and support other protocols (e.g., CGI and CGI variants) for interfacing with web servers. They also allow web applications to leverage services like reverse proxy, clustering, redundancy, and load balancing—services that improve performance and reliability and allow developers to focus less on infrastructure and more on coding.

To make matters more confusing, many web servers and some application servers are referred to, or refer to themselves, as web application servers.

The bottom line is that today’s most popular web servers and application servers are hybrids of both. Most of the increasingly rich applications you use today feature a combination of static web content and dynamic application content, delivered via a combination of web server and application server technologies.

Open source web servers and application servers

The market is flooded with web servers and application servers—too many to list here. Instead, we thought it might be more valuable to list the most popular free, open source options available:


Nginx (Link resides outside IBM) is an open source web server that includes reverse proxy, load balancing, mail proxy, and HTTP cache capabilities. Commercial, supported versions of Nginx are also available, at Nginx, Inc. (Link resides outside IBM). According to the internet research and cybercrime prevention company Netcraft (Link resides outside IBM), Nginx served or proxied nearly 38% of all the world’s websites and over 25% of the million busiest sites as of December, 2019. World-known enterprise Nginx users include Dropbox, Netflix, and Zynga.

Apache HTTP Server

First released in 1995, Apache HTTP Server (also just known as ‘Apache’) is another very popular free, open source web server that, until very recently, powered more websites than any other web server—71% at its peak—before being overtaken by Nginx in April, 2019. As of December 2019, Apache served over 24% of all sites worldwide and 31% of the million busiest sites.

Apache Tomcat

Apache Tomcat (Link resides outside IBM) is an open source application server that executes Java Servlets, renders and delivers web pages that include JavaServer Page code, and serves Java Enterprise Edition (Java EE) applications. Released in 1998, Tomcat is the most widely used open source Java application server.


Glassfish (Link resides outside IBM) is an open source Java EE application server launched by Sun Microsystems in 2006, and it is hosted today by the Eclipse Foundation (Link resides outside IBM). Like most Java application servers, Glassfish supports Java Servlets, Enterprise JavaBeans (EJB), and more, but it can also function as a web server, serving up web content in response to HTTP requests.

Web servers, application servers, and IBM Cloud®

Web servers and application servers will remain part of application modernization as the demand for better customer experiences and more applications impacts business and IT operations. When it comes to meeting such demands, a move toward greater automation will help. Ideally, it would start with small, measurably successful projects, which you can then scale and optimize for other processes and in other parts of your organization. 

Working with IBM, you’ll have access to AI-powered automation capabilities, including prebuilt workflows, to help accelerate innovation by making every process more intelligent. 

Apache tomcat web server configuration file

Take the next step:

  • IBM offers HTTP Server, a web server included with other products such as IBM® WebSphere® Application Server. IBM HTTP Server is based on the Apache HTTP Server and provides all Apache features, plus IBM enhancements. Find out more about IBM HTTP Server Powered by Apache, Version 9.0.
  • IBM WebSphere Liberty is a Java EE application server designed for cloud native applications and microservices. WebSphere Liberty is built on the Open Liberty project (Link resides outside IBM) that provides an open source Java EE and MicroProfile core.
  • Read about the results of one company’s transition to the IBM WebSphere Application Server Liberty Profile on IBM Cloud.
  • Register to get the IBM Application Modernization Field Guide (PDF, 2.9 MB) to learn how to accelerate modernization, improve developer productivity and enhance operational efficiency and standardization. 
  • Check out a blog post about IBM WebSphere Hybrid Edition, which enables a phased approach to digital transformation.

Get started with an IBM Cloud account today.

Featured products