At work we have many Spring apps running on one tomcat server. Some of the apps have their own domains with a virtualhost in apache that rewrites requests from /url to /context_root/url.
This is all fine and good except for when I use some of springs tag libs that handle urls. An example is the <form:form> tag which creates an action of /context_root/form and takes the user away from /. Now, the app still works when that happens but management doesn't want to see the context root.
What is the best way to tackle this?
In case anyone stumbles into this, I did end up finding the answer.
With Tomcat you can have multiple hosts. So I setup a host with my app as the default webapp. Here's an example:
Add another Host to server.xml
<Host name="lilhug.mydomain.com" appBase="lilhug"
unpackWARs="true" autoDeploy="true"
xmlValidation="false" xmlNamespaceAware="false"/>
Create some files and directories
mkdir $CATALINA_HOME/lilhug
mkdir $CATALINA_HOME/conf/Catalina/lilhug.mydomain.com
If you want the Tomcat manager for this host
cd $CATALINA_HOME/conf/Catalina
cp localhost/manager.xml lilhug.mydomain.com
Then restart tomcat and you're good. Deploy the lilhug app to / using the /manager running at your new host or copy the war to $CATALINA_HOME/lilhug/ROOT.war
Related
I have inherited a WAMP setup, but needed my http://localhost to point to a different directory "C:/Users/[user.name]/htdocs" due to many dependencies.
I made the following changes in httpd.conf
DocumentRoot "C:/Users/[user.name]/htdocs"
<Directory "C:/Users/[user.name]/htdocs">
where the original path was "c:/wamp/www/"
Now the WAMP default path for phpMyAdmin http://localhost/phpMyAdmin is not working anymore.
Is it possible to fix that via either C:\wamp\alias\phpmyadmin.conf or httpd-vhosts.conf somehow?
Can I suggest a better solution to your requirement to have a site running that does not live in the WAMPServer default location i.e. \wamp\www or \wamp\www\somefolder
If you revert all your httpd.conf changes to the out of the box state and then create a Virtual Host to run the site you have located in your \user.... folder.
Virtual Hosts are a standard Apache feature that allows you to run may sites from a single instance of Apache, a bit like a shared hosting package setup.
You would then have the benefits of the WAMPServer homepage running on localhost and all the other alias's tools as well.
You can then run your site using a nice url for example sitename.dev and the virtual host definition also allows you to setup any site specific requirements without effecting any other site you may want to run.
There is a HowTo Setup Virtual Hosts here on SO
I'm running tomcat and I want to change the default webroot so that it points to another location. Is there a way to find out what's running tomcat or where the default webroot is set as I can't find httpd.conf which is where I believe it's usually set?
Cheers,
Alexei Blue.
**UPDATE:**
It's been a long time since I looked at this question that I forgot about it. In the end it turned out that we were using Apache HTTPD to accept requests from port 80. From there we had the webroot and ProxyPass rules set in the /etc/httpd/conf/virtual-hosts/default.conf file (these can also be set in /etc/httpd/conf/httpd.conf). From there we had several tomcat instances running, all hosted on different ports which are setup in apache-tomcat-x/conf/server.xml.
When I wrote this question I was trying to setup a new tomcat instance to run an application in development and was told I would need to change the webroot to access my application, which was incorrect. Instead what I needed was to include a ProxyPass rule so that when my application name was recognised in the URL, HTTPD would send the request to the correct tomcat instance to be processed.
E.g.
www.domain.com/myApplication
In /etc/httpd/conf/virtual-hosts/default.conf
ProxyPass /myApplication/ ajp://127.0.0.1:<ajp_port>/myApplication/
ProxyPassReverse /myApplication/ ajp://127.0.0.1:<ajp_port>/myApplication/
Where the ajp_port is setup in apache-tomcat-x/conf/server.xml. I needed to ensure that non of the ports conflicted with other tomcat instances so remember to check all ports i.e. Shutdown, HTTP, HTTP with SSL, AJP etc.
Tomcat doesn't use httpd.conf, that is an apache file. The location of the individual webapps are kept in their individual web.xml files, but the location of all the configs are in ../tomcat6/conf/server.xml and web.xml
Is it where the files come from you want to move, or where it compiles and executes them from?
As #Woody says, Tomcat does not use httpd.conf files: that's an Apache httpd thing (httpd is a web server, Tomcat is a Java application server).
You didn't mention what OS you are using or what package management software you are using (e.g. yum, apt, etc.) so I'll give you generic information as if you had downloaded and installed Tomcat directly from apache.org (which I usually recommend people do for a number of reasons).
Tomcat keeps its server-wide configuration in the conf/server.xml file in the Tomcat base installation directory (often called $CATALINA_BASE for convenience): here, you configure things like what types of connectors (e.g. HTTP, HTTPS, AJP, etc.) to use and which ports they should listen to, clustering configuration, session persistence, global JNDI and realm resources. There are also conf/web.xml and conf/context.xml files that define defaults for all webapps deployed on that instance of Tomcat, but it's best to leave those files alone unless you have a really good reason to modify them.
When you want to deploy a webapp (under the default configuration), all you need to do is drop a .WAR file into the $CATALINA_BASE/webapps/ directory and the webapp will be deployed into a "context path" (aka URL prefix) that matches the name of the file minus the ".WAR" suffix. So, if you have a WAR file called mygreatwebapp.war, then it will be deployed such that your clients can reach it at http://yourhost/mygreatwebapp/. There is a special name you can give a WAR file so that it has an empty context path: if you name your WAR file ROOT.war (case matters), then your webapp can be reached at http://yourhost/. (If you would rather use exploded-WAR directories instead of WAR files, everything above still applies except the directories simply don't have the .war extension).
Given your original question, it sounds like all you want to do is drop a ROOT.war file into $CATALINA_BASE/webapps (or replace the one that is already there): this will deploy whatever webapp you want into the URL space that you might call the "default webroot".
Update
If you want to change the directory where all the webapps live for a host, you can modify $CATALINA_BASE/conf/server.xml and change the <Host>'s appBase attribute to point to, say, /cfusion/main/www/. That will deploy all the WAR files and directories in /cfusion/main/www/ as separate webapps.
If you just want to serve a single webapp from an arbitrary location, you may create a deployment file under $CATALINA_BASE/conf/[EngineName]/[HostName]/[appname].xml. This is a standard file like META-INF/context.xml and contains a <Context> element except that you will have to specify a docBase which points to your webapp (e.g. /cfusion/main/www/mywebapp).
I'd like run jsp files directly from /srv/http without deploying them the Tomcat-way. For example, I want to be able to create symbolic link to my webapp directory (e.g. /home/user/myapp/) in /srv/http and access some app's page through http://localhost/myapp/page.jsp.
Is this possible and how would I set this up?
NOTE: This is not for production. We have to use JSP at university and I want to be able to quickly test my pages.
Open the server.xml of your Tomcat. Assuming if your are using Tomcat 6.x+ then it would be at /tomcatDir/conf/server.xml.
Make an entry with your path
<Context path="/myapp" docBase="yourPathGoesHere" debug="0" reloadable="true" />
Restart Tomcat if already running.
What I did at the moment was creating a symlink in /var/lib/tomcatX/webapps to my project path. This is not the answer I was looking for though, but it is a way to deploy an app without much work.
(X in the above path means your Tomcat version)
If you set <Host name="localhost" appBase="/srv/http"> then all of the directories in it will be deployed as web applications.
If you want /srv/http to be the ROOT application/directory add a file: tomcat/conf/Catalina/localhost/ROOT.xml
with the Context docBase="/srv/http", rather than adding a Context definition to server.xml - this has been strongly discouraged for years.
We have development team of 10 people working on Linux platform our application is hosted on Apache server
Now what i want if every developer is having own codebase in his directory
he can have his own httpd conf file which uses his code base and his port on that server
and whenever he changes the code base he needs run only his apache process
and there is no need to start , restart the apache server as other people should not get disturbed
so can we do this listening same server on different ports with different DocumentRoot and no need to start or restart the whole apache server only individual process of apache need to be started if any changes are done in the local conf file of that user
You need not get into the complexity of managing virtual hosts.
You can create alias for each developer which will point to his directory.
http://httpd.apache.org/docs/1.3/mod/mod_alias.html#alias
Eg :
servername.com/dev1/
in httpd conf point dev1 to developer's working folder.
Developer can update code see the result at the above url without restarting server.
I haven't been able to figure out how to deploy multiple grails applications with Apache/Tomcat where a virtual host is mapped to each grails app
I can get it so that
http://virtualhost1.example.com/myGrailsApplication-0.1/
works, but what I want is for
http://virtualhost1.example.com/
to go directly to my application. A lot of tutorial sites on the web just have you make your web app the "ROOT" one, but that won't work in a mutiple grails-app virtual host environment.
I tried using the
<Host name="virtualhost1.example.com" ...> </Host>
tags in the tomcat/conf/server.xml file, but it didn't seem to do anything (and, yes, I restarted tomcat each time I changed it.)
I also tried everything I could think of in my apache config file for the virtual host, and couldn't get it to work.
So, how can I get rid of the app name in the URL when I have multiple grails webapps, virtual hosts, and I don't want my webapp to be "ROOT"?
I'm assuming that you are using mod_jk to connect Apache & Tomcat. If so, You will have to have to configure virtual hosting within Tomcat as well as Apache (multiple <Host> declarations in your conf/server.xml)
This basically means that you'll have two <Host ...> declarations within conf/server.xml. They will have different names, and appBase, but you will still have to name the war ROOT.war
The example that they gave was:
<Engine name="Catalina" defaultHost="ren">
<Host name="ren" appBase="renapps"/>
<Host name="stimpy" appBase="stimpyapps"/>
</Engine>
After you've configured the DNS of your virtual '<host>s'(much like Apache) you'll have to put your ROOT.war(s) into separate folders {renapps,stimpyapps} instead of the default 'webapps' folder
This method works, but there is another method using mod_proxy instead of mod_jk. I'm not that familiar with mod_proxy but basically you would have the connector handle translating the root context to the actual context. So after its configured it would proxy & forward requests sent to http://virtualhost1.example.com/ to the right context within Tomcat (/myGrailsApplication-0.1/)
Let us know what you find! Anyone else do this with mod_proxy?