Welcome to OGeek Q&A Community for programmer and developer-Open, Learning and Share
Welcome To Ask or Share your Answers For Others

Categories

0 votes
195 views
in Technique[技术] by (71.8m points)

java - Setup a Tomcat vhost by context.xml. Not in the server.xml

  1. old way to setup a vhost in server.xml
     <Host name="www.mysite.com"  appBase="webapps"
            unpackWARs="true" autoDeploy="true">
          <Context path="" docBase="sample" reloadable="true" />

this works, I can see contents in the <tomcat_home>/webapps/sample.

  1. as mentioned in Tomcat docs.

It is NOT recommended to place elements directly in the server.xml file. This is because it makes modifying the Context configuration more invasive since the main conf/server.xml file cannot be reloaded without restarting Tomcat. Default Context elements (see below) will also overwrite the configuration of any elements placed directly in server.xml. To prevent this, the override attribute of the element defined in server.xml should be set to true.

Individual Context elements may be explicitly defined:

  • In an individual file at /META-INF/context.xml inside the application files. Optionally (based on the Host's copyXML attribute) this may be copied to $CATALINA_BASE/conf/[enginename]/[hostname]/ and renamed to application's base file name plus a ".xml" extension.

  • In individual files (with a ".xml" extension) in the $CATALINA_BASE/conf/[enginename]/[hostname]/ directory. The context path and version will be derived from the base name of the file (the file name less the .xml extension). This file will always take precedence over any context.xml file packaged in the web application's META-INF directory.

So I create someting in server.xml

    <Host name="www.mysite.com"  appBase="webapps"
            unpackWARs="true" autoDeploy="true">
    </Host>

and then place a context.xml in <tomcat_home/conf/Catalina/www.mysite.com/, and its content is

    <Context  docBase="sample" reloadable="true" />

This don't work, it return a 404 page.

So what's the right way to set vhost by context ?

Thanks.


与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
Welcome To Ask or Share your Answers For Others

1 Reply

0 votes
by (71.8m points)
等待大神答复

与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
OGeek|极客中国-欢迎来到极客的世界,一个免费开放的程序员编程交流平台!开放,进步,分享!让技术改变生活,让极客改变未来! Welcome to OGeek Q&A Community for programmer and developer-Open, Learning and Share
Click Here to Ask a Question

...