配置Tomcat 域名解析 tomcat/conf server.xml

Posted Dong诗原

tags:

篇首语:本文由小常识网(cha138.com)小编为大家整理,主要介绍了配置Tomcat 域名解析 tomcat/conf server.xml相关的知识,希望对你有一定的参考价值。

  1 初始文件:
  2 <?xml version=1.0 encoding=utf-8?>
  3 <!--
  4   Licensed to the Apache Software Foundation (ASF) under one or more
  5   contributor license agreements.  See the NOTICE file distributed with
  6   this work for additional information regarding copyright ownership.
  7   The ASF licenses this file to You under the Apache License, Version 2.0
  8   (the "License"); you may not use this file except in compliance with
  9   the License.  You may obtain a copy of the License at
 10 
 11       http://www.apache.org/licenses/LICENSE-2.0
 12 
 13   Unless required by applicable law or agreed to in writing, software
 14   distributed under the License is distributed on an "AS IS" BASIS,
 15   WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
 16   See the License for the specific language governing permissions and
 17   limitations under the License.
 18 -->
 19 <!-- Note:  A "Server" is not itself a "Container", so you may not
 20      define subcomponents such as "Valves" at this level.
 21      Documentation at /docs/config/server.html
 22  -->
 23 <Server port="8005" shutdown="SHUTDOWN">
 24 
 25   <!--APR library loader. Documentation at /docs/apr.html -->
 26   <Listener className="org.apache.catalina.core.AprLifecycleListener" SSLEngine="on" />
 27   <!--Initialize Jasper prior to webapps are loaded. Documentation at /docs/jasper-howto.html -->
 28   <Listener className="org.apache.catalina.core.JasperListener" />
 29   <!-- Prevent memory leaks due to use of particular java/javax APIs-->
 30   <Listener className="org.apache.catalina.core.JreMemoryLeakPreventionListener" />
 31   <!-- JMX Support for the Tomcat server. Documentation at /docs/non-existent.html -->
 32   <Listener className="org.apache.catalina.mbeans.ServerLifecycleListener" />
 33   <Listener className="org.apache.catalina.mbeans.GlobalResourcesLifecycleListener" />
 34 
 35   <!-- Global JNDI resources
 36        Documentation at /docs/jndi-resources-howto.html
 37   -->
 38   <GlobalNamingResources>
 39     <!-- Editable user database that can also be used by
 40          UserDatabaseRealm to authenticate users
 41     -->
 42     <Resource name="UserDatabase" auth="Container"
 43               type="org.apache.catalina.UserDatabase"
 44               description="User database that can be updated and saved"
 45               factory="org.apache.catalina.users.MemoryUserDatabaseFactory"
 46               pathname="conf/tomcat-users.xml" />
 47   </GlobalNamingResources>
 48 
 49   <!-- A "Service" is a collection of one or more "Connectors" that share
 50        a single "Container" Note:  A "Service" is not itself a "Container", 
 51        so you may not define subcomponents such as "Valves" at this level.
 52        Documentation at /docs/config/service.html
 53    -->
 54   <Service name="Catalina">
 55   
 56     <!--The connectors can use a shared executor, you can define one or more named thread pools-->
 57     <!--
 58     <Executor name="tomcatThreadPool" namePrefix="catalina-exec-" 
 59         maxThreads="150" minSpareThreads="4"/>
 60     -->
 61     
 62     
 63     <!-- A "Connector" represents an endpoint by which requests are received
 64          and responses are returned. Documentation at :
 65          Java HTTP Connector: /docs/config/http.html (blocking & non-blocking)
 66          Java AJP  Connector: /docs/config/ajp.html
 67          APR (HTTP/AJP) Connector: /docs/apr.html
 68          Define a non-SSL HTTP/1.1 Connector on port 8080
 69     -->
 70     <Connector port="8080" protocol="HTTP/1.1" 
 71                connectionTimeout="20000" 
 72                redirectPort="8443" />
 73     <!-- A "Connector" using the shared thread pool-->
 74     <!--
 75     <Connector executor="tomcatThreadPool"
 76                port="8080" protocol="HTTP/1.1" 
 77                connectionTimeout="20000" 
 78                redirectPort="8443" />
 79     -->           
 80     <!-- Define a SSL HTTP/1.1 Connector on port 8443
 81          This connector uses the JSSE configuration, when using APR, the 
 82          connector should be using the OpenSSL style configuration
 83          described in the APR documentation -->
 84     <!--
 85     <Connector port="8443" protocol="HTTP/1.1" SSLEnabled="true"
 86                maxThreads="150" scheme="https" secure="true"
 87                clientAuth="false" sslProtocol="TLS" />
 88     -->
 89 
 90     <!-- Define an AJP 1.3 Connector on port 8009 -->
 91     <Connector port="8009" protocol="AJP/1.3" redirectPort="8443" />
 92 
 93 
 94     <!-- An Engine represents the entry point (within Catalina) that processes
 95          every request.  The Engine implementation for Tomcat stand alone
 96          analyzes the HTTP headers included with the request, and passes them
 97          on to the appropriate Host (virtual host).
 98          Documentation at /docs/config/engine.html -->
 99 
100     <!-- You should set jvmRoute to support load-balancing via AJP ie :
101     <Engine name="Catalina" defaultHost="localhost" jvmRoute="jvm1">         
102     --> 
103     <Engine name="Catalina" defaultHost="localhost">
104 
105       <!--For clustering, please take a look at documentation at:
106           /docs/cluster-howto.html  (simple how to)
107           /docs/config/cluster.html (reference documentation) -->
108       <!--
109       <Cluster className="org.apache.catalina.ha.tcp.SimpleTcpCluster"/>
110       -->        
111 
112       <!-- The request dumper valve dumps useful debugging information about
113            the request and response data received and sent by Tomcat.
114            Documentation at: /docs/config/valve.html -->
115       <!--
116       <Valve className="org.apache.catalina.valves.RequestDumperValve"/>
117       -->
118 
119       <!-- This Realm uses the UserDatabase configured in the global JNDI
120            resources under the key "UserDatabase".  Any edits
121            that are performed against this UserDatabase are immediately
122            available for use by the Realm.  -->
123       <Realm className="org.apache.catalina.realm.UserDatabaseRealm"
124              resourceName="UserDatabase"/>
125 
126       <!-- Define the default virtual host
127            Note: XML Schema validation will not work with Xerces 2.2.
128        -->
129       <Host name="localhost"  appBase="webapps"
130             unpackWARs="true" autoDeploy="true"
131             xmlValidation="false" xmlNamespaceAware="false">
132 
133         <!-- SingleSignOn valve, share authentication between web applications
134              Documentation at: /docs/config/valve.html -->
135         <!--
136         <Valve className="org.apache.catalina.authenticator.SingleSignOn" />
137         -->
138 
139         <!-- Access log processes all example.
140              Documentation at: /docs/config/valve.html -->
141         <!--
142         <Valve className="org.apache.catalina.valves.AccessLogValve" directory="logs"  
143                prefix="localhost_access_log." suffix=".txt" pattern="common" resolveHosts="false"/>
144         -->
145 
146       </Host>
147     </Engine>
148   </Service>
149 </Server>
150 
151 配置后的server.xml:
152 <?xml version=1.0 encoding=utf-8?>
153 <!--
154   Licensed to the Apache Software Foundation (ASF) under one or more
155   contributor license agreements.  See the NOTICE file distributed with
156   this work for additional information regarding copyright ownership.
157   The ASF licenses this file to You under the Apache License, Version 2.0
158   (the "License"); you may not use this file except in compliance with
159   the License.  You may obtain a copy of the License at
160 
161       http://www.apache.org/licenses/LICENSE-2.0
162 
163   Unless required by applicable law or agreed to in writing, software
164   distributed under the License is distributed on an "AS IS" BASIS,
165   WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
166   See the License for the specific language governing permissions and
167   limitations under the License.
168 -->
169 <!-- Note:  A "Server" is not itself a "Container", so you may not
170      define subcomponents such as "Valves" at this level.
171      Documentation at /docs/config/server.html
172  -->
173 <Server port="8005" shutdown="SHUTDOWN">
174 
175   <!--APR library loader. Documentation at /docs/apr.html -->
176   <Listener className="org.apache.catalina.core.AprLifecycleListener" SSLEngine="on" />
177   <!--Initialize Jasper prior to webapps are loaded. Documentation at /docs/jasper-howto.html -->
178   <Listener className="org.apache.catalina.core.JasperListener" />
179   <!-- Prevent memory leaks due to use of particular java/javax APIs-->
180   <Listener className="org.apache.catalina.core.JreMemoryLeakPreventionListener" />
181   <!-- JMX Support for the Tomcat server. Documentation at /docs/non-existent.html -->
182   <Listener className="org.apache.catalina.mbeans.ServerLifecycleListener" />
183   <Listener className="org.apache.catalina.mbeans.GlobalResourcesLifecycleListener" />
184 
185   <!-- Global JNDI resources
186        Documentation at /docs/jndi-resources-howto.html
187   -->
188   <GlobalNamingResources>
189     <!-- Editable user database that can also be used by
190          UserDatabaseRealm to authenticate users
191     -->
192     <Resource name="UserDatabase" auth="Container"
193               type="org.apache.catalina.UserDatabase"
194               description="User database that can be updated and saved"
195               factory="org.apache.catalina.users.MemoryUserDatabaseFactory"
196               pathname="conf/tomcat-users.xml" />
197   </GlobalNamingResources>
198 
199   <!-- A "Service" is a collection of one or more "Connectors" that share
200        a single "Container" Note:  A "Service" is not itself a "Container", 
201        so you may not define subcomponents such as "Valves" at this level.
202        Documentation at /docs/config/service.html
203    -->
204   <Service name="Catalina">
205   
206     <!--The connectors can use a shared executor, you can define one or more named thread pools-->
207     <!--
208     <Executor name="tomcatThreadPool" namePrefix="catalina-exec-" 
209         maxThreads="150" minSpareThreads="4"/>
210     -->
211     
212     
213     <!-- A "Connector" represents an endpoint by which requests are received
214          and responses are returned. Documentation at :
215          Java HTTP Connector: /docs/config/http.html (blocking & non-blocking)
216          Java AJP  Connector: /docs/config/ajp.html
217          APR (HTTP/AJP) Connector: /docs/apr.html
218          Define a non-SSL HTTP/1.1 Connector on port 8080
219     -->
220     <Connector port="80" protocol="HTTP/1.1"     
221               maxHttpHeaderSize="8192"
222         maxThreads="150" minSpareThreads="25"
223         maxSpareThreads="75"
224         enableLookups="false" redirectPort="8443"
225         acceptCount="100"
226         connectionTimeout="20000" disableUploadTimeout="true"
227         URIEncoding="UTF-8"/>
228  //改端口为80,运行项目时就不需要在网站路径中添加:8080,直接http://localhost/abc就行了。
229 URIEncoding="UTF-8"设定默认编码方式为UTF-8
230 URIEncoding="UTF-8"    <!-- A "Connector" using the shared thread pool-->
231     <!--
232     <Connector executor="tomcatThreadPool"
233                port="80" protocol="HTTP/1.1" 
234                connectionTimeout="20000" 
235                redirectPort="8443" />
236     -->           
237     <!-- Define a SSL HTTP/1.1 Connector on port 8443
238          This connector uses the JSSE configuration, when using APR, the 
239          connector should be using the OpenSSL style configuration
240          described in the APR documentation -->
241     <!--
242     <Connector port="8443" protocol="HTTP/1.1" SSLEnabled="true"
243                maxThreads="150" scheme="https" secure="true"
244                clientAuth="false" sslProtocol="TLS" />
245     -->
246 
247     <!-- Define an AJP 1.3 Connector on port 8009 -->
248     <!-- <Connector port="8009" protocol="AJP/1.3" redirectPort="8443" /> -->
249 
250 
251     <!-- An Engine represents the entry point (within Catalina) that processes
252          every request.  The Engine implementation for Tomcat stand alone
253          analyzes the HTTP headers included with the request, and passes them
254          on to the appropriate Host (virtual host).
255          Documentation at /docs/config/engine.html -->
256 
257     <!-- You should set jvmRoute to support load-balancing via AJP ie :
258     <Engine name="Catalina" defaultHost="localhost" jvmRoute="jvm1">         
259     --> 
260     <Engine name="Catalina" defaultHost="localhost">
261 
262       <!--For clustering, please take a look at documentation at:
263           /docs/cluster-howto.html  (simple how to)
264           /docs/config/cluster.html (reference documentation) -->
265       <!--
266       <Cluster className="org.apache.catalina.ha.tcp.SimpleTcpCluster"/>
267       -->        
268 
269       <!-- The request dumper valve dumps useful debugging information about
270            the request and response data received and sent by Tomcat.
271            Documentation at: /docs/config/valve.html -->
272       <!--
273       <Valve className="org.apache.catalina.valves.RequestDumperValve"/>
274       -->
275 
276       <!-- This Realm uses the UserDatabase configured in the global JNDI
277            resources under the key "UserDatabase".  Any edits
278            that are performed against this UserDatabase are immediately
279            available for use by the Realm.  -->
280       <Realm className="org.apache.catalina.realm.UserDatabaseRealm"
281              resourceName="UserDatabase"/>
282 
283       <!-- Define the default virtual host
284            Note: XML Schema validation will not work with Xerces 2.2.
285        -->
286       <Host name="www.baidu.com" xmlNamespaceAware="false"
287          xmlValidation="false" autoDeploy="true" unpackWARs="true" appBase="webapps" debug="0"> 
288     <Context reloadable="true" path="" docBase="项目名称"/>
289 //这段代码绑定域名,和设定用域名默认打开的文件,假设项目名称为abc,放在webapps下,然后直接在网页地址栏输入域名:www.baidu.com 就能直接访问项目abc了。如果还有其他项目也放在webapps下,用www.baidu.com/其他项目名称,也可以访问。
290         <!-- SingleSignOn valve, share authentication between web applications
291              Documentation at: /docs/config/valve.html -->
292         <!--
293         <Valve className="org.apache.catalina.authenticator.SingleSignOn" />
294         -->
295 
296         <!-- Access log processes all example.
297              Documentation at: /docs/config/valve.html -->
298         <!--
299         <Valve className="org.apache.catalina.valves.AccessLogValve" directory="logs"  
300                prefix="localhost_access_log." suffix=".txt" pattern="common" resolveHosts="false"/>
301         -->
302 
303       </Host>
304     </Engine>
305   </Service>
306 </Server>

 

以上是关于配置Tomcat 域名解析 tomcat/conf server.xml的主要内容,如果未能解决你的问题,请参考以下文章

配置tomcat监听80端口配置tomcat虚拟机tomcat日志

Tomcat配置Tomcat的虚拟主机 日志

访问域名时直接访问默认的工程,执行默认的方法—备忘录《二》

Tomcat(tomcat虚拟主机,Tomcat日志,单机多实例配置实战,JVM设置和连接数设置)

tomcat 不同域名 不同端口访问项目

tomcat部署第二个Java应用