Should I run Tomcat myself or Apache + Tomcat?

I was wondering if Tomcat can be run both in the web server and in the container? On the other hand, it seems that the correct way to scale your webapp is to use Apache HTTP listening on port 80 and connect it to Tomcat while listening to another port? Are both methods acceptable? What is used today? What is the difference? How is this done on most major websites?

Thanks.

+8
tomcat apache
source share
2 answers

Placing Apache (or any other web server) in front of application servers (Tomcat) is good for a number of reasons.

The first consideration relates to static resources and caching.

Tomcat will probably also serve a lot of static content, or even in dynamic content it will send some caching directives to browsers. However, every browser that first hits your tomcat will force tomcat to send a static file. Since request processing in Tomcat is a bit more expensive than in Apache (due to the fact that Apache is super-optimized and uses very low-level materials that are not always available in Tomcat, because Tomcat extracts much more information from the request than Apache requires and so on) .d ...), it might be better if the static files are an Apache server.

Since configuring Apache for part of the content and Tomcat for the rest or URL space is a difficult task, it is usually simpler for Tomcat to serve everything with the correct cache headers, and Apache in front of it, grabbing the content, serving it in the required browser and caching it. so that another browser, once in the same file, will be served directly from Apache, without even bothering Tomcat.

Besides static files, it may also not be necessary to update many dynamic elements every milliseconds. For example, json, loaded with a home page that tells the user how much material is in your database, is a costly query running thousands of times that can be safely executed every hour or so without causing users to get angry. So, tomcat can serve json with the correct cache directive for one hour, Apache will cache the json fragment and serve it in any browser that requires it for one hour. Of course, there are many other ways to implement it (caching filter, JPA cache that caches the request, etc.), but sending the correct cache headers and using Apache as a reverse proxy is quite simple, REST is compatible and scales well.

Another consideration is load balancing. Apache comes with a good load balancer module that can help you scale your application across multiple Tomcat instances, assuming your application can scale horizontally or work in a cluster.

The third consideration concerns ulrs, headers, etc. From time to time, you may need to change some URLs or delete or redefine some headers. For example, before a major upgrade, you may need to disable browser caching for several hours so that browsers do not use outdated data (such as reducing DNS-TTL before switching servers), or move the old application to another URL space, or rewrite old urls for new ones whenever possible. While reconfiguration of servlets inside your web.xml files is possible, and filters can work wonders if you use a framework that interprets URLs that you may need to do a lot of work on your Sitemaps or similar stuff.

Having Apache or another web server in front of Tomcat can help significantly change only Apache configuration files with modules such as mod_rewrite.

So, I always recommend having Apache httpd before Tomcat. Small connection processing overheads are usually recovered through resource caching, and additional configuration work is recovered the first time you need to move URLs or handle some headers.

+14
source share

It depends on your network and how you want to configure security.

If you have DMZ with two firewalls, with applications deployed in the second firewall, it makes sense to have an Apache or IIS instance between the two firewalls to handle security calls and proxies on the application server. If it is acceptable to host a Tomcat instance in the DMZ, you can do it. The only drawback that I see is that you have to open the port in the second firewall to access the database inside. This may jeopardize the database.

Another consideration is traffic. You don't say anything about traffic, server sizes, and possible load balancing and clustering. The load balancer in front of the application server cluster is most likely to be stored in the second firewall. A Tomcat instance is able to handle traffic on its own, but there are always volume limits depending on the equipment used and what the application does with each request. It is practically impossible to give a yes or no answer without detailed information about the application.

Find a site for "tomcat without apache" - before it was asked. I voted to close before finding duplicates.

+1
source share

All Articles