The difference between Apache and Tomcat and why they need to work together


Publication date:January 1, 2021



INFOMARTION > The difference between Apache and Tomcat and why they need to work together

summary

I would like to explain the difference between Apache and Tomcat and why it is necessary to link them, which I could not find a satisfactory answer to even after asking my seniors and searching the Internet when I was a newcomer. It is sometimes said that Apache is a web server (executes static processing) and Tomcat is a servlet container (executes dynamic processing) (as I was told by a senior colleague when I was a newcomer), but Tomcat also has web server functions if you examine it carefully. However, if you examine Tomcat carefully, you will find that it also has web server functions. Then you end up going back to the question of why Apache and Tomcat need to work together. For those of you who are wondering, I would like to explain the difference between Apache and Tomcat and why they need to be linked.

Table of Contents

  1. Reasons for linking Apache and Tomcat
  2. Apache Features
  3. Tomcat Features
  4. consideration
  5. summary

1. Reasons for linking Apache and Tomcat

Let me first conclude with a difference in role specialization. Apache specializes in web server functions, while Tomcat specializes in dynamic processing using Java.

The reason I wrote "difference in expertise" is that Tomcat itself has functions as a web server. This may be a bit extreme, but if there is a system in which Apache and Tomcat are linked, it is not impossible to realize almost the same system using only Apache and only Tomcat.

1-1. What are the differences in expertise?

In considering the difference in role specialties, I feel that it is difficult to understand because we are suddenly comparing Apache and Tomcat. I think it is easier to understand if you think in terms of Tomcat and DB server. This may be a bit extreme, but it is possible to create an application using only Tomcat without setting up a DB server. For example, it would be possible to create an application that manages user information in xml or property and authenticates login based on that information. In reality, however, if you look at general Web systems, most systems manage user information in a DB and reference data from Tomcat to the DB server. If you think about why, it is because that way you can develop apps more efficiently.

Sometimes people explain the "merits" and "demerits" of linking Apache and Tomcat, but this is not about merits and demerits. When asked about the "merits" and "demerits" of linking Tomcat and a DB server, I would answer that the roles are different to begin with. Apache and Tomcat also have different roles to begin with.

1-2. What is Apache?

Having mentioned that the roles are different, I would now like to explain what the roles of Apache and Tomcat are.

Once again, Apache is officially called "Apache HTTP Server". Apache is a web server, but to explain its role in a nutshell, it is responsible for parsing requests.

Specifically, the following will be used

  • Filter (allow/deny requests) for specific IP addresses
  • Redirect for specific URL
  • Rejection of specific URL
  • Encryption of communication by SSL
  • Allocate processing to specific servers based on request

The above is just one example, and there are many more, but in short, the role of Apache (the web server) is to handle requests received from users.

It is the job of Tomcat to decide what kind of response to make based on the specific request. The point that should not be misunderstood is that Apache is not allowed to create responses. Even if Tomcat is linked to a DB server, there is no problem to implement dynamic pages in Apache as long as they are simple responses, just as Tomcat maintains simple data (such as a list of messages) on its side. The key is what can be processed most efficiently and managed neatly.

1-3. What is Tomcat?

The official name for Tomcat is "Apache Tomcat". Tomcat is a servlet container, and to put it simply, its role is to perform dynamic processing based on requests.

Specifically, the following will be used

  • Register data based on request information
  • Create dynamic pages and responses based on request information
  • Determine the user based on the request information and create different responses for each user.

Basically, Tomcat is responsible for returning pages that are not fixed pages to the user.

The point that should not be misunderstood here is that it does not mean that static pages (e.g., html) should not be placed in Tomcat. If a team is designed to manage all html on the Tomcat side, there is no problem with placing static pages on Tomcat. In this case, too, the key point is what can be processed most efficiently and managed neatly.

2. Apache Features

I would like to introduce some of Apache's features. Apache provides a number of modules (files in which processes are packaged). You can load a module, enter the required configuration values, and then use the functionality. I would like to describe what modules are available.

2-1. Ability to process requests concurrently

The module "mpm_prefork_module" is the relevant module. There are also "mpm_worker_module" and "mpm_event_module," which have almost the same functions.

Set values like the following

<IfModule mpm_prefork_module>
    StartServers             5
    MinSpareServers          5
    MaxSpareServers         10
    MaxRequestWorkers      250
    MaxConnectionsPerChild   0
</IfModule>

When the server is started, "5" processes can be started and "5" can be processed in parallel at the same time, and up to "250" can be processed in parallel when a large number of requests come in.

2-2. Rewriting the request URL

The module "rewrite_module" is the relevant module.

Set values like the following

<IfModule rewrite_module>
  RewriteEngine on
  RewriteCond %{HTTPS} off
  RewriteRule ^(.*)$ https://%{HTTP_HOST}%{REQUEST_URI} [R=301,L]
</IfModule>

If a request comes in at http, it will be returned to the user to request again at https.

2-3. Access control by IP address

This one is a little different from the module, but it controls access by IP address.

If you enter the following, you will not be able to access from IPs other than "1.0.16.0/20", "1.0.64.0/18", and "1.1.64.0/18".

<Directory />
    order deny,allow
    deny from all
    allow from 1.0.16.0/20
    allow from 1.0.64.0/18
    allow from 1.1.64.0/18
</Directory>

3. Tomcat Features

I would like to explain the function of Tomcat.

3-1. Ability to return web pages dynamically using Java

Tomcat's expertise lies in its "ability to return web pages dynamically using Java. In general, Java processing is not created entirely on its own, but is used in conjunction with Java libraries (modules in Apache) that are created by various organizations.

  • Dynamically generate responses based on user request parameters
  • Output log files in a specific format
  • Create and edit Excel files
  • Determine if a zip file has a password

Complex processing such as the above can be achieved simply by adding a library and calling the library. I believe that the role of Tomcat is to make it easy to implement such complex processing.

4. consideration

I have explained that the difference between Apache and Tomcat is "a difference in role specialization," but both Apache (Apache HTTP Server) and Tomcat (Apache Tomcat) are created by the same Apache Software Foundation. Apache is written in C and Tomcat is written in Java, which may be the reason for the difference in language, but I think the reason why they are not combined into one is because of their different roles.

Tomcat Home Page(http://tomcat.apache.org/)The web server functionality was also quite extensive when we looked at the

  • SSL/TLS (encryption of communications)
  • SSI (the ability to embed another HTML within HTML)
  • Rewrite (URL rewriting function) etc.

Apache is a high-performance web server, but it has many functions that are not used, so the Apache Software Foundation may have made it so that Tomcat alone can run independently without Apache. However, it is still better to include Apache when fine control of requests is required.

5. summary

We have described the differences between Apache and Tomcat and why they need to be linked.

I thought the answer to this question was difficult to understand because Tomcat has full functionality as a web server. I think it is a good idea to think about the cooperation between Apache and Tomcat, keeping in mind that Tomcat's function as a web server is not its main function (it is not specialized as a web server).

Thank you for taking the time to read this to the end.




■INFORMATION

Please click here to go to the top page of INFORMATION.


■PROFILE

Please click here to view the profile.


■For inquiries, please contact

For inquiries about the article, please contact us here.