Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How do Apache httpd and Tomcat work together?

I am inheriting a project involving a Java web app whose backend is powered by an Apache httpd/Tomcat combo. The web server is being used to serve back JS, static content, and to perform general load balancing, and Tomcat is serving back JSPs via a single WAR file.

I will be receiving access to the code base later on today or tomorrow, but wanted to try and do some research ahead of time.

My question can be summed up as: how do these two work together?

  • Who first receives HTTP requests?
  • How does httpd know when to forward JSP requests on to Tomcat, or to just respond to a request itself?
  • How does httpd "pass" the request to, and "receive" the response from, Tomcat? Does it just "copy-n-paste" the request/response to a port Tomcat is listening on? Is there some sort of OS-level interprocess communication going on? Etc.

These are just general questions about how the technologies collaborate with each other. Thanks in advance!

like image 452
IAmYourFaja Avatar asked Mar 20 '12 17:03

IAmYourFaja


People also ask

Is httpd and Tomcat same?

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.

Does Tomcat need httpd?

Yes. It's very common. Apache httpd will often be used as a reverse proxy since tomcat us usually run on port 8080/8443. httpd is running on port 80/443; the standard ports for the service.

Can we run Apache and Tomcat on same server?

Absolutely, there is no reason they can not run on the same server. By default the web server runs on port 80 and tomcat runs on port 8080 so there are no port conflicts.


1 Answers

Who first receives HTTP requests?

Apache, almost certainly. There could be admin processes that talk directly to Tomcat, though.

How does httpd know when to forward JSP requests on to Tomcat, or to just respond to a request itself?

From its configuration. The specifics will vary. It might, for instance, be using mod_jk or mod_jk2, in which case you'll find JkMount directives in the config files, e.g.:

JkMount /*.jsp ajp13_worker

...which tells it to pass on requests at the root of the site for files matching *.jsp to the ajp13_worker, which is defined in the workers.properties file.

Or it could be set up in a simple HTTP reverse-proxy arrangement. Or something else.

How does httpd "pass" the request to, and "receive" the response from, Tomcat?

It depends on the configuration; it could be HTTP, it could be AJP, or it could be using some other module.

Does it just "copy-n-paste" the request/response to a port Tomcat is listening on?

Sort of. :-) See the reverse-proxy link above.

Is there some sort of OS-level interprocess communication going on?

Yes. AFAIK, it's all socket-based (rather than, say, shared memory stuff), which means (amongst other things) that Tomcat and Apache need not be running on the same machine.

like image 98
T.J. Crowder Avatar answered Oct 23 '22 22:10

T.J. Crowder