First and foremost you need to understand how Tomcat handles WARs and presents them as webapps.
A WAR, of course, is a JEE-standard Web ARchive file and can be deployed to Tomcat either in its native form (ZIP) or in "exploded" form (unzipped). By default, Tomcat will explode a WAR file for its own internal convenience.
Deploying a webapp consists of taking a WAR and associating it with a context path. The context path is the part of the URL that comes after the server information (name and optionally port) and before the WAR-relative resource paths. For most webapps, the default is that Tomcat takes the name of the exploded WAR. So if I unzip mywebapp.war into TOMCAT_HOME/webapps, then I can access it via http://localhost:8080/mywebapp.
ROOT is a special case, since "/" is not a valid directory name, which is why Tomcat maps http://localhost:8080/ (no context path) to TOMCAT_HOME/webapps/ROOT.
There are other ways to deploy WARs. In fact, you don't actually have to put your WAR in TOMCAT_HOME/webapps if you configure a Tomcat Context, but that's a more advanced feature.
So, as you can see, you can deploy many webapps very easily in a single Tomcat server. Each one lives under a different URL context path.
But what if instead of using a different context path, you want a different host path? Say instead of http://localhost:8080/mywebapp you want the URL http://mywebapp.coderanch.com:8080/.
There are two ways to do this. One is to set up virtual hosts in Tomcat and map DNS for the virtual hostname to point to the Tomcat server. This isn't as simple as it sounds.
So there's also another way, which is generally preferred and that's to front Tomcat with a reverse proxy server such as Apache, Nginx, or IIS.
The advantages of setting up this extra server are many:
1. You can host both JEE and non-JEE (php, for example) webapps at the same host.
2. You can avoid having to explicitly override the port number in the URL (http defaults to 80, but Tomcat can only listen on port 80 if it's running insecure).
3. You can rewrite URLs to be virtually anything you want with relatively little effort.
4. It's a lot easier to set up SSL for something like Apache than it is to set up SSL for Tomcat.
So by using a reverse proxy, I can take an incoming request targeting https://www.mywebapp.com and route it to http://localhost:8009/mywebapp/. Note that the proxy-to-Tomcat pipeline connects to Tomcat's port 8009, not 8080.
Some people, when well-known sources tell them that fire will burn them, don't put their hands in the fire.
Some people, being skeptical, will put their hands in the fire, get burned, and learn not to put their hands in the fire.
And some people, believing that they know better than well-known sources, will claim it's a lie, put their hands in the fire, and continue to scream it's a lie even as their hands burn down to charred stumps.
posted 1 month ago
Yiou ever watch scrooge the musical, where they all sing that song Thank You very much, well that is what I am singing to you now.