What should Apache serve and what should Tomcat serve? - apache

I'm trying to set up Apache in front of Tomcat. What do I have Apache serve? I know Apache works better for static pages and images. I currently deploy a war file in Tomcat that contains static pages, images, and Flash files. Should I put those all on the Apache server? How to I reference those pages/images from the Tomcat application?
I would like to use Apache to decrease the war file size and hopefully serve images faster. Is there a good guide for setting up Apache and Tomcat and what to place where?

Do you have a problem with performance/load on your Tomcat server? Do it if you need to(performance, security, etc), but don't make things more complicated if you don't need to.
It used to be the standard to front Tomcat with an Apache server, but recent versions of Tomcat can(and often times are) used as both the HTTP Server and the Servlet Container.
Take a look at the Tomcat Connector FAQ for information on the subject.
Why should I integrate Apache with
Tomcat? (or not)
There are many reasons to integrate
Tomcat with Apache. And there are
reasons why it should not be done too.
Needless to say, everyone will
disagree with the opinions here. With
the performance of Tomcat 5 and 6,
performance reasons become harder to
justify.
...
Speed. Apache is faster at serving
static content than Tomcat. But unless
you have a high traffic site, this
point is useless. But in some
scenarios, tomcat can be faster than
Apache httpd. So benchmark YOUR site.
Tomcat can perform at httpd speeds
when using the proper connector (APR
with sendFile enabled). Speed should
not be considered a factor when
choosing between Apache httpd and
Tomcat

Related

how to organize files in Tomcat and Apache server?

I just installed both Apache server and Tomcat, and I read that I should put static html pages in Apache and put dynamic pages, like JSP, Servlets, and all other full Java applications in Tomcat. Specifically, where should they go respectively?
For instance, should html files be placed under /var/www/html?
And all other files under /opt/apache-tomcat-7.0.34/webapps/?
Any tutorial for this? Thanks a lot.
The typical ways to forward requests from Apache to Tomcat involve the use of mod_proxy, mod_proxy_ajp or mod_jk (there might be more). All of them are well documented and basically involve requests that hit your Apache to be forwarded to tomcat if they match certain criteria (like path names) - all nonmatching requests will be handled by Apache, however you configure this one.
However, I'm seconding on JB Nizet's comment: Dividing the serving of different content to Apache and Tomcat is an optimization. It's arguable if you should add this complexity (not that it's too complex, but it's more to do than not separating it) when you don't have the need. E.g. if your nonoptimized website can handle 1000 concurrent users, but you'll rarely have more than 10 - don't bother.

When to Use Apache vs. Apache+Tomcat?

Since simply using Apache can be enough to run many Web applications, when and why do people also use Tomcat in addition to Apache?
Apache Tomcat is a webserver and Java servlet container in one, while Apache HTTPD is just a plain webserver (often with only PHP support). They use Apache Tomcat when they want be able to run Java/JSP/Servlet. It can be added to an existing Apache HTTPD / PHP setup. Or the other way round, they bring Apache HTTPD in front of Apache Tomcat to be able to have a "This site is in maintenance" page when Tomcat is been shutdown for some upgrade/maintenance.
For communication between Apache HTTPD and Apache Tomcat, the Tomcat Connector is usually been used. It's also known as mod_jk.
Maybe too late to answer.
"Apache" is the name of a foundation that write open-source software. Apache HTTPD is a web server written in portable C (when people say "Apache", they usually mean Apache HTTPD.) It mostly serves static content by itself, but there are many add-on modules (some of which come with Apache itself) that let it modify the content and also serve dynamic content written in Perl, PHP, Python, Ruby, or other languages.
Tomcat is primarily a servlet/JSP container. It's written in Java. It can serve static content, too, but its main purpose is to host servlets and JSPs. Although it's possible to get Tomcat to run Perl scripts and the like, you wouldn't use Tomcat unless most of your content was Java.
It's actually possible to use both Apache and Tomcat together, so that Apache serves the static content, and Tomcat the Servlets and JSPs. Depending on various factors, this may or may not be a good idea.

Should there always be an Apache in front of a Tomcat (and why)? [duplicate]

I'm trying to set up Apache in front of Tomcat. What do I have Apache serve? I know Apache works better for static pages and images. I currently deploy a war file in Tomcat that contains static pages, images, and Flash files. Should I put those all on the Apache server? How to I reference those pages/images from the Tomcat application?
I would like to use Apache to decrease the war file size and hopefully serve images faster. Is there a good guide for setting up Apache and Tomcat and what to place where?
Do you have a problem with performance/load on your Tomcat server? Do it if you need to(performance, security, etc), but don't make things more complicated if you don't need to.
It used to be the standard to front Tomcat with an Apache server, but recent versions of Tomcat can(and often times are) used as both the HTTP Server and the Servlet Container.
Take a look at the Tomcat Connector FAQ for information on the subject.
Why should I integrate Apache with
Tomcat? (or not)
There are many reasons to integrate
Tomcat with Apache. And there are
reasons why it should not be done too.
Needless to say, everyone will
disagree with the opinions here. With
the performance of Tomcat 5 and 6,
performance reasons become harder to
justify.
...
Speed. Apache is faster at serving
static content than Tomcat. But unless
you have a high traffic site, this
point is useless. But in some
scenarios, tomcat can be faster than
Apache httpd. So benchmark YOUR site.
Tomcat can perform at httpd speeds
when using the proper connector (APR
with sendFile enabled). Speed should
not be considered a factor when
choosing between Apache httpd and
Tomcat

How much slower is serving static content from Tomcat?

So, I have a webapp with a fair amount of JSPs, servlets, alot of which are using IceFaces. Obviously, most of this will have to stay in Tomcat.
However, I've been told that static content (HTML, Images, etc.) is slower on Tomcat than a pure webserver like Apache. My understanding is that when you're using Tomcat as a stand-alone webserver, it's using a version of Apache in the first place. I may be mistaken on this, of course.
But what is the penalty for serving static images or files from Tomcat? Is it worth breaking out into its own webserver for a low volume site?
See the Tomcat Connector FAQ for some information. For modern versions of Tomcat, the performance difference is much smaller than it used to be. For a low volume site, there is no reason that you cannot supply all content with Tomcat.
I agree except in two circumstances
Tomcat's SSL using JSSE is noticeably slower. There are native versions that can be plugged in, but that tends to be more painful. In general the SSL is a bit less straightforward than the well-understand Apache Httpd server
Fronting with an HTTpd server gives more flexibility re virtual web hosts etc. Tomcat is not as flexible in this regard. Unsurprisingly it lacks all the options in Apache :). An obvious nice one is built in compression of static files is very easy to add in Apache. It's not hard in tomcat extra, but it's more work.
You are mistaken. Apache Httpd Server is a totally different beast and has no code shared with Tomcat.
If neither is an issue, than yeah use tomcat by itself

Is Apache Tomcat built on Apache Web Server platform?

Recently our Software Analytic provider (NETTRACKER) sent us a plugin in order to be able to capture visitors in a better way. This plugin is for Apache 1.x and Apache 2.x. They said and I quote
that since Apache Tomcat is built on Apache HTTP server the configuration of the plugin should be the same.
I have looked for a httpd.conf in our tomcat deployment but we cannot find one, the only configuration that is similar to that one is the server.xml under the /conf directory.
If someone has better information regarding these two incredible products (Apache HTTP server and Apache Tomcat) I will greatly appreciate to draw the differences.
EDIT:
In case you are curious we know that Apache Web Server and Tomcat can work together using the mod_jk option and other proxys. But this will be too complex for our deployment.
Apache Tomcat and Apache HTTP are completely different server technologies. It is impossible to use a plugin for Apache HTTP server with Tomcat.
Apache HTTP server is developed in C and so are the plug-ins. On the contrary Tomcat is now completely developed in Java. Tomcat doesn't only serve static content, but it can also serve JSP pages and servlets.
Tomcat is used for hosting Java Web Applications. It can sure serve static content - you can host a web application using only Tomcat. Secure connections are supported and the performance is also very good (comparable with the performance of HTTP server).
A plain installation of Apache serves static content. Using the appropriate plug-ins, HTTP requests can be redirected to an application server (Tomcat, JBoss, Glassfish) or a script language interpreter (PHP). With this way dynamic content can be generated. The big advantages of Apache are the numerous plug-ins available, which allows administrators to configure and monitor web sites any way they want and that is the most widespread server available. This makes it the most secure solution, since it is thoroughly tested and any discovered flaw is corrected very quickly.
The best solution would be to use Tomcat proxied by an Apache server. It isn't so difficult to set up. If you can't do this, then you can't take advantage of Apache's plug-ins.
You see this confusion all the time. Many people think that Apache is a web server where in reality it is the name of an organization that has a web server project called "The Apache HTTP Server Project". In short the web server is called HTTPD (D as in daemon or Unix process).
Tomcat is another Apache project. This project implements a Java servlet engine to serve JSP pages and servlets. Tomcat and HTTPD have nothing to do with each other. However, you can set up HTTPD and Tomcat so that they work together. This way you can have HTTPD serve all static content, do URL rewriting and much more fancy stuff that the built in Tomcat web server can't do (or can't do very well). Whenever a JSP page is requested, HTTPD will pass the request on to Tomcat. Tomcat will process the request and will hand the output back to HTTPD which in turn will send it to the client.
Apache has many interesting projects. E.g. there is also a project called Geronimo which is a Java Enterprise server (J2EE). You can e.g. choose to embed Tomcat inside Geronimo to handle requests for JSP's and servlets where Geronimo does the more enterprisy stuff (LDAP, Messaging etc.). And you guessed it probably already, you can use HTTPD as a static content server for Geronimo as well.
totally bogus. Apache httpd plugins are written in C, Tomcat is pure Java.
Tomcat is a Java servlet engine. It can be hosted under Apache or IIS or quite a number of other external facing web servers. It sounds like you may be currently running your Tomcat instance standalone...
If you serve the JSP/servlets off of port 8080 and have it do things standalone, on the same host machine that Apache is running on, this can allow you to have them loosely coupled. Having multiple web servers fielding independent requests is not recommended, especially if you want to use server-based authentication along with Apache. Typically, you have one outside facing server that shepherds everything through it... Apache does this quite well, and the plugin you mention probably relies on this type of setup (everything gets wired through Apache) for its features/capabilities, based on your brief description of it.
If you would like to serve up your Tomcat servlets under Apache, you could configure apache to forward a class of URIs to your tomcat server instances. you could achieve this type of forwarding through mod_rewrite. this is a slower option performance-wise, as it adds slight overhead on everything you server up. You could also proxy incoming requests via a CGI mechanism similarly, from Apache to Tomcat.
mod_jk will simplify deployment and increase performance for placing Tomcat into an Apache server config. It is pretty painless to configure if you follow the docs, so I am not sure what you mean by "too complex" for your deployment -- if you want Apache and have Tomcat already, it would seem only a matter of slight config changes to get mod_jk downloaded and installed.