683

What is the difference in terms of functionality between the Apache HTTP Server and Apache Tomcat?

I know that Tomcat is written in Java and the HTTP Server is in C, but other than that I do not really know how they are distinguished. Do they have different functionality?

Mark Harrison
  • 297,451
  • 125
  • 333
  • 465
kaybenleroll
  • 16,794
  • 16
  • 54
  • 66
  • 12
    I have added a summary in my blog, maybe it helps someone: http://www.tugay.biz/2014/11/what-is-tomcat-is-it-web-server-what.html – Koray Tugay Jan 16 '15 at 09:59
  • 47
    I was wondering exactly what the OP was asking, and I don't see why it was closed. Luckily there are answers. – Florian F May 27 '16 at 07:51
  • 7
    Apache web server and Apache Tomcat are two different tools tuned for different purposes. If we can no longer distinguish their use cases by facts and expertise then we are come to a sorry state. This drive to close "argumentative" questions has over-reached. Perhaps moderators need to be more informed and less opinionated. As @FlorianF says, at least there are answers now. – NeilG Nov 08 '18 at 01:46
  • 5
    Given the number of upvotes - this should not have be closed - but instead should be locked - as it is actually a very good question with useful answers. – simbro Jan 19 '19 at 10:34
  • 3
    The `closed` notice on this Question says it requires Answers to have objective content, but is expecting this Question will instead produce subjective Answer content - the majority of Answers seem to contain objective content (particularly the higher-voted Answers) rather than subjective - so this Question should be UN-CLOSED. The fears of subjectivity never really happened, and I don't agree the Question ever risked being subjective in the first place. – cellepo Dec 06 '19 at 22:34

8 Answers8

504

Apache Tomcat is used to deploy your Java Servlets and JSPs. So in your Java project you can build your WAR (short for Web ARchive) file, and just drop it in the deploy directory in Tomcat.

So basically Apache is an HTTP Server, serving HTTP. Tomcat is a Servlet and JSP Server serving Java technologies.

Tomcat includes Catalina, which is a servlet container. A servlet, at the end, is a Java class. JSP files (which are similar to PHP, and older ASP files) are generated into Java code (HttpServlet), which is then compiled to .class files by the server and executed by the Java virtual machine.

Vsevolod Golovanov
  • 4,068
  • 3
  • 31
  • 65
Bernie Perez
  • 12,513
  • 13
  • 46
  • 55
  • 1
    I know that Perl scripts can run in tomcat. Isn't this true? – serengeti12 May 19 '11 at 13:54
  • 55
    What do you intend by "Apache is [...] serving HTTP"? Isn't Tomcat also serving (hypertext aka) HTTP? Why can't Tomcat simply be a "mod_java" Apache module? Can you explain? – Peterino Jan 19 '12 at 09:09
  • 31
    Tomcat is a servlet container. A servlet, at the end, is a Java class. JSP files (which are similar to PHP oder ASP files) are generated into Java code (HttpServlet), which is then compiled to .class files by the server and executed by the Java virtual machine. - Apart from that, this forum here explains the difference between Apache HTTPD and Tomcat pretty well: http://www.coderanch.com/t/85182/Tomcat/difference-between-Apache-HTTP-server – Peterino Jan 19 '12 at 15:44
  • 8
    @Peterino "Why can't Tomcat simply be a "mod_java" Apache module?". There is a "mod_jk" Apache module used to interface Apache with Tomcat. The question is "why shouldn't Tomcat bring a full, simple and plain old HTTP server instead of forcing an admin to configure two environments, one of which must be recompiled for the specific target platform?" – usr-local-ΕΨΗΕΛΩΝ Mar 28 '12 at 15:30
  • 17
    Tomcat does indeed bring with it a capable web server. Tomcat is a Servlet/JSP container *and* also offers a web server. Tomcat's web server is quite good, able to handle most small and medium web site needs. With support for Java NIO and 64-bit memory, even some larger scale web sites may be served well by Tomcat's Catalina module. For various reasons, some folks choose to ignore Catalina and instead use Tomcat's Servlet capabilities behind the Apache `httpd` web server product. – Basil Bourque May 21 '14 at 07:15
  • 25
    Correction to my comment: Coyote is the module in Tomcat responsible for web serving. Catalina is the module that does Servlets. Jasper is the module that handles JSPs. – Basil Bourque May 21 '14 at 07:25
  • 2
    @BasilBourque So Tomcat has its own webserver and it does not use Apache httpd? – Koray Tugay Nov 25 '14 at 18:20
  • 19
    @KorayTugay Yes. `Tomcat = ( Web Server + Servlet container + JSP environment )`. The web server is ON by default when you run Tomcat’s `startup.sh` script, listening on port 8080 for incoming connections (HTTP calls). Tomcat is pure Java, with its own web server implementation (Coyote). The [Apache HTTP Server](https://en.wikipedia.org/wiki/Apache_HTTP_Server) (AHS), in contrast, has a completely separate implementation of a web server, using native C/C++ code. AHS is very flexible and powerful, but is often overkill. Tomcat's own web server works very well. Use AHS only if truly needed. – Basil Bourque Nov 25 '14 at 18:46
  • 2
    @Peterino for your question: `What do you intend by "Apache is [...] serving HTTP"?` It is a server that receives & interprets http requests to fetch static html files on file system and send the file content as response. where as apache tomcat the same http request either triggers fetching of static html files OR triggers the servlet java program via container. – overexchange Dec 16 '14 at 01:27
  • @BasilBourque, Wrong. `tomcat = webserver`. And `webserver = servlet container + JSP environment + etc`. The servlet container is [a **part** of](http://java.dzone.com/articles/what-servlet-container) the web server. – Pacerier Jan 16 '15 at 08:42
  • 7
    @Pacerier Nope, I afraid it is your statement that is incorrect. A Servlet container is certainly *not* necessarily part of a web server. Tomcat has frequently been used as only a Servlet container connected by a bridge to the [Apache HTTP Server](http://en.m.wikipedia.org/wiki/Apache_HTTP_Server). The web browsers only see the Apache HTTP Server. If a request involves a Servlet, Apache relays the request to Tomcat. The web server and Servlet container in such a case are completely separate, two different apps running in two different processes, one native and the other Java-based. – Basil Bourque Jan 16 '15 at 09:32
  • 1
    @BasilBourque, There is no Apache anywhere at all. I'm referring to your comment `Tomcat = ( Web Server + Servlet container + JSP environment )`. In this setup, the Tomcat is the web server. `tomcat = webserver`. The tomcat webserver includes the servlet container and provides the JSP environment. `tomcat webserver = servlet container + JSP environment + etc`. – Pacerier Jan 17 '15 at 15:15
  • 1
    This answer might be entirely correct, but it means very little to me when it comes to distinguishing Tomcat and HTTPD. – Merchako Apr 25 '16 at 15:40
  • So Apache is just a substitute of nginx? It does not directly talk to Java (without mod_jk), but only talks HTTP, HTTPS, FastCGI, etc? So roughly Tomcat works same (functionally) as Apache + mod_jk? – Franklin Yu Sep 07 '17 at 19:21
  • @FranklinYu it is more accurate to say nginx is a substitute of apache httpd. Tomcat is a full fledged application server, like Mongrel,Unicorn or Zope. There's no exact mapping between the Java and non-Java worlds, due to the whole everything-in-Java-runs-in-a-VM architecture. (for .NET, IIS uses a mod_jk-like layer called ISAPI to execute the .NET CLR). – cowbert Jan 24 '18 at 19:15
  • 1
    Your use of "Apache" in this answer is extremely confusing, they are both "Apache." It's difficult to distinguish which you're referring to - HTTP Server or Tomcat. – gangelo Mar 22 '19 at 13:00
124

In addition to the fine answers above, I think it should be said that Tomcat has it's own HTTP server built into it, and is fully functional at serving static content too. Depending on your java virtual machine configuration it can actually outperform going through traditional connectors in apache such as mod_proxy and mod_jk.

That said a fully optimized Tomcat server should serve static files fast and if you have Java servlets, JSPs and ColdFusion files in addition to static content you may find tomcat does an excellent job by itself.

ethyreal
  • 3,659
  • 2
  • 21
  • 25
  • 3
    True. And many people still use an extra Apache setup besides their Tomcat.. which is unnecessary in most cases. – Marco Schoolenberg Jan 04 '17 at 16:20
  • 7
    The most powerful part of apache http that few other servers support is ability to reroute and rewrite the request before application has to see it, namely through `mod_rewrite` engine and conditional environment injection. `mod_proxy` provides rudimentary load balancing (and combined with mod_jk provides rudimentary sticky session/shared state between load balanced tomcat instances). – cowbert Jan 24 '18 at 19:19
88
  1. Apache is a general-purpose http server, which supports a number of advanced options that Tomcat doesn't.
  2. Although Tomcat can be used as a general purpose http server, you can also set up Apache and Tomcat to work together with Apache serving static content and forwarding the requests for dynamic content to Tomcat.
A5C1D2H2I1M1N2O1R2T1
  • 190,393
  • 28
  • 405
  • 485
Satish Dhiman
  • 1,036
  • 1
  • 8
  • 15
  • Isn't all web is static at the end? My understanding is, Tomcat generates "a" static content (dynamically) then Apache will serve this. So Tomcat will never actually serve dynamic content or anything, it will only generate it when required. – Koray Tugay Nov 25 '14 at 19:49
  • 13
    @KorayTugay You are confusing your terms. "Generate it when required" is exactly what "dynamic" means, and is the very opposite of "static". The main purpose of the Apache HTTP Server is to serve static content, while the main purpose of Servlet technology is to generate content on-the-fly (dynamic content). – Basil Bourque Jan 16 '15 at 09:42
  • 1
    @BasilBourque I was confused with Tomcat actually serving content here. It will only generate the content, it will not serve it when used together with Apache Http Server. Probably you are right and I am just confused but to me I would still say, when used together, Apache serves, Tomcat generates static content when required. If not Apache is used, Coyote in Tomcat will do the serving, while Catalina and Jesper are generating the dynamic content. – Koray Tugay Jan 16 '15 at 10:02
  • 3
    @KorayTugay Yes, your last comment is correct. If using Apache HTTP Server + Tomcat, then web browsers only "see" AWS with no clue that Tomcat is working behind the curtains. AWS is a middle-man between the web browser clients and Tomcat. If using Tomcat alone, then the Coyote module in Tomcat takes the place of AWS to field requests from web browser clients. I recommend the latter (Tomcat alone) unless you know you have very special needs that would be better addressed by AWS. – Basil Bourque Jan 16 '15 at 10:08
  • @BasilBourque did you mean AHS (Apache HTTP Server) instead of AWS? – chick3n0x07CC Dec 20 '20 at 16:02
  • @chick3n0x07CC Yes, I meant "AHS" for [*Apache HTTP Server*](https://en.wikipedia.org/wiki/Apache_HTTP_Server). Siri’s spell checker must have overrode my typing. Thanks. – Basil Bourque Dec 21 '20 at 00:50
  • @KorayTugay Actually, your last comment had a erroneous statement: "Tomcat generates static content" is a contradiction in terms. Static content on a web server means files of HTML, CSS, JavaScript, images, etc. that are already written, just sitting on storage, produced earlier, waiting for a user to request them. Generated content means web pages produced on-the-fly at the moment a user’s request arrives, producing the text of some HTML, CSS, and JavaScript *not* already saved as a file. For example, generated content may be produced to represent the results of a live query to the database. – Basil Bourque Dec 21 '20 at 00:53
  • @BasilBourque I see, thank you for the explanation. – Koray Tugay Dec 21 '20 at 02:44
  • @BasilBourque so could you edit and fix that in your comment? To avoid possible misunderstandings by future readers. – chick3n0x07CC Dec 21 '20 at 13:51
  • @chick3n0x07CC Comments are frozen after five minutes. Cannot be edited. – Basil Bourque Dec 21 '20 at 17:53
31

Tomcat is primarily an application server, which serves requests to custom-built Java servlets or JSP files on your server. It is usually used in conjunction with the Apache HTTP server (at least in my experience). Use it to manually process incoming requests.

The HTTP server, by itself, is best for serving up static content... html files, images, etc.

levand
  • 8,440
  • 3
  • 41
  • 54
  • 11
    I doubt `Tomcat is primarily an application server` statement. – Rachel Mar 28 '12 at 16:05
  • 7
    tomcat is primarily *meant* to be an application server. though it *does* server static content as well. – Scalable Nov 12 '13 at 15:08
  • 5
    Yes Tomcat is indeed primarily an application server, if the term is meant in the sense of a Servlet container generating dynamic content delivered to web browsers. As one of the first Servlet containers, that is Tomcat's reason for being. – Basil Bourque May 21 '14 at 07:22
  • 1
    tomcat is not an application server, it is a web server. http://javajee.com/web-server-web-container-and-application-server – Prateek Mishra May 19 '17 at 18:14
  • 1
    @PrateekMishra Based on the link you provided, your statement that tomcat is a **web server** is incorrect; it is (primarily) a **web container**, also known as a **servlet container**. – skomisa Apr 14 '18 at 01:24
22

an apache server is an http server which can serve any simple http requests, where tomcat server is actually a servlet container which can serve java servlet requests.

Web server [apache] process web client (web browsers) requests and forwards it to servlet container [tomcat] and container process the requests and sends response which gets forwarded by web server to the web client [browser].

Also you can check this link for more clarification:-

https://sites.google.com/site/sureshdevang/servlet-architecture

Also check this answer for further researching :-

https://softwareengineering.stackexchange.com/a/221092

Rohith M
  • 31
  • 1
  • 6
streak
  • 1,121
  • 1
  • 19
  • 28
  • https://sites.google.com/site/sureshdevang/servlet-architecture As you explains this give the better view – Akitha_MJ Jun 07 '20 at 20:18
15

If you are using java technology(Servlet/JSP) for making web application you will probably use Apache Tomcat. However, if you are using other technologies like Perl, PHP or ruby, its better(easier) to use Apache HTTP Server.

vishal
  • 159
  • 1
  • 2
  • 10
    This answer makes no sense to me. The first sentence is wrong in that there are many other Servlet/JSP containers besides Tomcat, some quite popular such as Jetty, JBoss/Wildfly, Glassfish, WebSphere, and many more. While popular, Tomcat does not dominate, with only a minority of market share. As for the second sentence, Tomcat is often used as a Servlet container behind Apache HTTP Server. And PHP etc. are [often used with several other web Servers](http://en.m.wikipedia.org/wiki/PHP#Use) such as Nginx, Lighttpd, and others. – Basil Bourque Jan 16 '15 at 09:57
  • to be fair, we use tomcat exclusively for serving our serverside software (as its all java based) but we run this under apache due to the advanced features of apache – George c Apr 14 '21 at 09:37
  • Do ServletsJsps are used for dynamic content as well? Since tomcat and apache http server are able to serve static content and not dynamic content. I've little knowledge regarding this @BasilBourque – Prateek Gautam Jan 31 '22 at 08:52
  • 1
    @Matuagkeetarp Yes, Servlet and JSPs are for creating dynamic content. Read the [Wikipedia pages](https://en.wikipedia.org/wiki/Jakarta_Servlet), [tutorials](https://www.oracle.com/java/technologies/instant-tutorial.html), and [specs](https://jakarta.ee/specifications/). Apache Tomcat is one of several available products for running the Servlets/JSPs that you write. Eclipse Jetty is a direct competitor to Tomcat, both are popular and successful. – Basil Bourque Jan 31 '22 at 13:51
4

Well, Apache is HTTP webserver, where as Tomcat is also webserver for Servlets and JSP. Moreover Apache is preferred over Apache Tomcat in real time

yadul
  • 73
  • 1
  • 20
    This question is quite old, and your answer seems to duplicate ones that have been posted long ago. Answers are appreciated but new answers should help add to the conversation. – GargantuChet Sep 24 '12 at 20:10
-1

Apache is an HTTP web server which serve as HTTP.

Apache Tomcat is a java servlet container. It features same as web server but is customized to execute java servlet and JSP pages.

Bertram Gilfoyle
  • 9,899
  • 6
  • 42
  • 67
  • 1
    yes answer is bit confusing as @ Basil Bourque said above " Coyote is the module in Tomcat responsible for web serving, Catalina is the module that does Servlets. and Jasper is the module that handles JSPs " now it gives clarity on how "TOMCAT FEATURES Same as web server customized to execute java servlet and JSP pages!!!! " – Dev Jul 22 '14 at 07:07