简体   繁体   中英

Tomcat Virtual Host configuration confusion

I'm deploying my first Groovy/Grails application onto a Tomcat 6 server and I'm running into some confusion trying to configure virtual hosts on Tomcat. I run the deployment script for Tomcat that comes with Grails and it copies the WAR file to the Tomcat server under the webapps folder and also uncompresses it (or maybe Tomcat does that I'm not sure). So I have the following:

C:\Program Files\Tomcat\webapps\myapp.WAR
C:\Program Files\Tomcat\webapps\myapp\{all files from the WAR}

I can access this without any issues by using the DNS name for the server:

http://server.dns.com/myapp/

However, I'm running into issues trying to create a virtual host for this. I've added the following lines to the server.xml file:

<Host name="www.fancynewdomainname.com" appBase="webapps/myapp"
      unpackWARs="true" autoDeploy="true"
      xmlValidation="false" xmlNamespaceAware="false">
</Host>

but all I get is blank page.

I've tried to Google this issue, but the more I read the more I just get confused.

PS As a side note I noticed that after adding this virtual host to the server.xml file I also have the following folder:

C:\Progrma Files\Tomcat\work\Catalina\www.fancynewdomainname.com\

but it seems to be mainly empty with just a few empty folders in it that mimic the folders in the WAR file.

Try removing the context name from the appBase attribute, eg appBase="webapps" .

Edit:

If I understand correctly what you are trying to achieve, I think you need to define a separate appBase for each virtual host, eg:

<Host name="www.somedomainname.com" appBase="webapps" ...
<Host name="www.fancynewdomainname.com" appBase="webapps2" ...

Then inside each appBase, rename the main webapp to "ROOT.war" (so it can be accessed without the context name).

Changing the original server.xml lines to the following seems to make things work:

<Host name="www.fancynewdomainname.com" appBase="webapps"
      unpackWARs="true" autoDeploy="true"
      xmlValidation="false" xmlNamespaceAware="false">
  <Context path="" docBase="myapp"/>
</Host>

Basically I changed the appBase to be just "webapps" and added the line containing the Context definition which does the actual pointing to the correct app under webapps.

In the Grails Config.groovy you can change the context by adding the following:

grails.app.context = "${appName}-helloworld"

By the way it is Tomcat that unpacks the war. Setting the unpackWARs to false would stop that from happening.

Another way to handle this is to put Apache HTTP server in front of this and then proxy to your Tomcat server. This provides an extra layer of protection also.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM