I am in need of your help. I have a web application that I am migrating to new servers.Currently this application is hosted at the root of tomcat. so I have this in my server.xml :
This application's static content is hosted by Apache web server and dynamic requests are passed to tomcat.
This is apache configuration:
The first page loaded when one enters https://myservername is landing.html, here depending on the option user selects, he is forwarded to sso/authentication-authorization site and when the login is successful he is forwarded back to
https://myservername/home page. I cannot change this url since other parties are using it and might have bookmarked it.
New migration rule is to keep tomcat configuration generalized so it can be managed by system engineers automatically. so my custom change in server.xml
will not be managed anymore. I need to find other way to keep it hosted at root of tomcat.
I followed tomcat documentation and found that
Individual context can be defined in individual files (with a ".xml" extension) in the $CATALINA_HOME/conf/[enginename]/[hostname]/ directory. The name of the file (less the .xml) extension will be used as the context path. Multi-level context paths may be defined using #, e.g. foo#bar.xml for a context path of /foo/bar. The default web application may be defined by using a file called ROOT.xml.
so I configured my context in a file called ROOT.xml at $CATALINA_HOME/conf/[enginename]/[hostname]/ but it still didnt deploy mywebapp at root. I tried another way by renaming context xml to mywebapp.xml too. No different result.
Though in the catalina logs I see something like ,
WARNING [localhost-startStop-1] org.apache.catalina.startup.HostConfig.deployDescriptor A docBase /usr/local/tomcat/webapps/mywebapp inside the host appBase has been specified, and will be ignored
Note I havent deleted or altered ROOT folder in webapps at all.
My webapp is available at servername/mywebapp but static content is not loaded because the static content is at doc root and the browser page source shows that it expects it at /mywebapp/css/ or mywebapp/img/ etc . So I think somehow the apache config ProxyPass /img ! etc is also not working in this case. This is not the problem when mywebapp is hosted at tomcat root though.
Can anyone help in identifying why my context config in $CATALINA_HOME/conf/[enginename]/[hostname]/ROOT.xml is not deploying mywebapp at root ? Or is there any other way I can achieve this?
The TOMCAT_HOME/conf/Catalina/localhost directory is one of the recommended places to put Context xml files, but the problem with the root context is that normally the context file's name determines what the Tomcat webapp context path will be. And that, incidentally, overrides the context path defined within the context XML file. One of Tomcat's quirks.
Your best bet to get what you want would be do delete the TOMCAT_HOME/webapps/ROOT directory contents and replace it with your own webapp, but personally, I don't much like doing that. You can get the same net effect by defining the Apache proxy path to be an ordinary context, since Apache will translate everything for you very nicely.
If you're using mod_proxy instead of mod_jk as your proxy mechanism - and it appears you are, you'd typically make your webapp be a VirtualHost (although a path within a non-J2EE app is fine, too), define your Java webapp under the context path "mywebapp" and code like this:
The path "/mywebapp" would never be visible to the outside world - it's strictly for intra-server proxy routing.
The static items are probably best handled by mod_rewrite, not by contortions in ProxyPass directives, and I should note that any static items specific to the Java webapp should be part of the Java webapp. Having Apache serve them separately stopped being more efficient about 15 years ago.
The TOMCAT_HOME/conf/Catalina/localhost directory is one of the recommended places to put Context xml files, but the problem with the root context is that normally the context file's name determines what the Tomcat webapp context path will be. And that, incidentally, overrides the context path defined within the context XML file. One of Tomcat's quirks
Explains why mywebapp is not going at the root of tomcat. So obviously this will not work for me.
Your best bet to get what you want would be do delete the TOMCAT_HOME/webapps/ROOT directory contents and replace it with your own webapp
I cannot do this. I am migrating this app from one production server to other. This doesnt seem the Standard.
I tried this long back and the requests expected the static content at tomcat side, something like /mywebapp/css/ , /mywebapp/img/ etc while the static content is hosted at /docroot/css etc on Apache side. So the screen source showed 404 for all static content.
I should note that any static items specific to the Java webapp should be part of the Java webapp. Having Apache serve them separately stopped being more efficient about 15 years ago.
I think this app was designed around a decade ago so no surprise they decided to host static content at Apache layer.
I am thinking to define a separate CATALINA_BASE and manage my application there. This way no future upgrade will disturb my custom set up of CATALINA_BASE and the generic set up model of standard software will remain intact.
Please let me know your thoughts.
When Tomcat is distributed, it comes with a default root webapp, but a lot of shops delete it for security or resource reasons, since it's not essential for Tomcat. And quite a few shops do simply replace it with their own webapps, although I'm not a big proponent of that myself. Strictly speaking, none of the standard webapps that come with Tomcat are essential and you can freely delete any of them. Some Tomcat distros have even made a point of distributing the Tomcat webapps separately from the Tomcat server. Even the admin apps are optional, and can be deleted depending on how paranoid you might happen to be.
CATALINA_HOME and CATALINA_BASE are shipped merged into each other, since that makes for the simplest Tomcat deployments when you don't need multiple Tomcat instances. I cannot guarantee that separating them merely for content purposes will make much difference, but if you feel more comfortable that way, go ahead. The bigger offense is when people make their webapps write into the WAR's WEB-INF or other directories. A WAR should be treated as read-only Failure to observe that precaution can and will cause Bad Things to happen.
Oh, a brief editorial:
Some people think that "Software doesn't wear out" and that they can continue to run the same code forever - a single payment up front to get the app written, and then the rest is all free.
That way lies danger. Software usually rots from the outside in. OS's change. Hardware changes. Languages and libraries change - although thankfully Java goes to a great deal of effort to minimize that last part. As time goes by, the technological debt from not keeping apps up to date mounts higher and higher until it becomes prohibitive and instead of small, relatively painless tweaks along the way, everything has to be handled in one massive go. And Murphy's Law predicts that that point will occur at a time when it's most embarrassing and expensive to have the system collapse. And when I say "embarrassing", I mean to the company and to the CEO, not just the IT department.
So if you've been trying to patch a decades-old app through one more band-aid, I suggest that you - and your superiors - take that into consideration.