Article Directory
1 server.xml virtual hosts and virtual directories
Previously developed JavaEE
sites are arranged Tomcat
, the directory is usually arranged $CATALINA_HOME/webapps/WebName
, so to access the site, then http://localhost
the context path must be added (ContextPath)/WebName
, and the operating environment generally http://www.abc.com
, the context path is empty.
This resulted in differences in the development environment and runtime environment, although JSP
by the <%=request.getContextPath()%>
resolve, but if replaced by other modules, for example Velocity
, it has not.
Tomcat 5
And Tomcat 6
profiles are: $CATALINA_HOME/conf/server.xml
Other versions of the Tomcat
configuration file with this
说明:
virtual host server.xml
for the Host
virtual directory Context
.
1.1 modify the port
Tomcat
The default WEB
port8080
<Connector port="8080" protocol="HTTP/1.1" connectionTimeout="20000" redirectPort="8443" />
注意
It is to modify the HTTP
agreement, that is protocol="HTTP/1.1"
, not the other.
1.2 increase the virtual directory
1.2.1 The easiest way
Directly to the JavaEE
website on the $CATALINA_HOME/webapps
directory, and then http://localhost/WebName
, WebName
as the name of the directory site;
1.2.2 Custom
The site's directory on the other, such as in /var/www/webapp
the directory, it is necessary to amend server.xml
the.
In </Host>
add the following before you can:
<Context path="/SpringMVC" docBase="/var/www/webapp/SpringMVC" workDir="/var/www/webtmp/SpringMVC" debug="5" reloadable="false" crossContext="true" />
You can at http: Access // localhost / SpringMVC, that is the addition of a virtual directory named SpringMVC in the host name localhost, of course, here's the name entirely according to individual dependent.
注意:
In the tomcat 5.5
following
is not recommended server.xml
to configure, but in /conf/context.xml
independent configuration. Because server.xml
it is not a dynamic resource re-loaded after server once started, to modify this file, you have to restart the server to reload. The context.xml
document is not, tomcat
the server periodically to scan the document. Once a file has been modified (timestamp changed), it will automatically reload the file, without the need to restart the server
Increased 1.3 Web Hosting
In fact, this is to say the focus of this article, which is the beginning of this article talking about the kind of case. Each developing a website through all http://localhost/WebName
forms of access, is not too much trouble?
1.3.1 modify the hosts file, add the host name
Linux
Systemhosts
files/etc/hosts
Windows
Systemhosts
filesC:\WINDOWS\system32\drivers\etc\hosts
such as you want to addwww.local.com
a host, then add a line in this file:127.0.0.1 www.local.com
that is when you visitwww.local.com
when, in fact, is to visit127.0.0.1
;
if prefer short domain that can be added:127.0.0.1 SpringMVC
1.3.2 modify the configuration file
In </Host>
adding a Host node and then:
<Host name="SpringMVC" appBase="/var/www/webapp/SpringMVC" unpackWARs="true" autoDeploy="false"
xmlValidation="false" xmlNamespaceAware="false" />
That adds a named SpringMVC
virtual host, of course, may be name="www.local.com"
, this depending on the circumstances.
Thus, the visit IP
is: http://SpringMVC
a.
1.3.3 Directory Settings
Host SpringMVC
's WEB
full file on the /var/www/webapp/SpringMVC
directory, an increase in the catalog ROOT
directory, add JavaEE
the site works, so you can http://SpringMVC
access your Web site, and less behind /SpringMVC
the string in IP
the running to maintain a consistent environment.
1.4 Other issues
By http://SpringMVC
accessing a SpringMVC
website;
by http://localhost
accessing a Tomcat
built-in site;
the hosts
file already know, SpringMVC
and localhost
all corresponding IP
is: 127.0.0.1
Well, by http://127.0.0.1
accessing the website is that it?
In the Host
parent node is: <Engine name="Catalina" defaultHost="localhost">
As can be seen from the above, defaultHost="localhost"
determines 127.0.0.1
which site, if access is set SpringMVC
to visitSpringMVC
1.5 server.xml file
Coming to an end this article, paste server.xml
the file contents:
<?xml version="1.0" encoding="utf-8" ?>
<Server port="8005" shutdown="SHUTDOWN">
<Listener className="org.apache.catalina.core.AprLifecycleListener" SSLEngine="on" />
<Listener className="org.apache.catalina.core.JasperListener" />
<Listener className="org.apache.catalina.mbeans.ServerLifecycleListener" />
<Listener className="org.apache.catalina.mbeans.GlobalResourcesLifecycleListener" />
<GlobalNamingResources>
<Resource name="UserDatabase" auth="Container"
type="org.apache.catalina.UserDatabase" description="User database that can be updated and saved"
factory="org.apache.catalina.users.MemoryUserDatabaseFactory"
pathname="conf/tomcat-users.xml" />
</GlobalNamingResources>
<Service name="Catalina">
<Connector port="8080" protocol="HTTP/1.1" connectionTimeout="20000" redirectPort="8443" />
<Connector port="8009" protocol="AJP/1.3" redirectPort="8443" />
<Engine name="Catalina" defaultHost="SpringMVC">
<Realm className="org.apache.catalina.realm.UserDatabaseRealm" resourceName="UserDatabase" />
<Host name="localhost" appBase="webapps" unpackWARs="true" autoDeploy="true" xmlValidation="false"
xmlNamespaceAware="false">
<!--HelloMule-->
<!--
<Context path="/mule" docBase="/var/www/webapp/Mule"
workDir="/var/www/webtemp/Mule" debug="5" reloadable="false"
crossContext="true" />
-->
</Host>
<Host name="SpringMVC" appBase="/var/www/webapp/SpringMVC"
unpackWARs="true" autoDeploy="false" xmlValidation="false"
xmlNamespaceAware="false" />
</Engine>
</Service>
</Server>