服务器之家:专注于服务器技术及软件下载分享
分类导航

云服务器|WEB服务器|FTP服务器|邮件服务器|虚拟主机|服务器安全|DNS服务器|服务器知识|Nginx|IIS|Tomcat|

服务器之家 - 服务器技术 - Tomcat - tomcat同时使用http和https访问的配置方法

tomcat同时使用http和https访问的配置方法

2021-09-01 16:25loading Tomcat

这篇文章主要介绍了tomcat同时使用http和https访问的配置方法,小编觉得挺不错的,现在分享给大家,也给大家做个参考。一起跟随小编过来看看吧

针对一个tomcat中有的项目需要使用ssl加密有些可以直接访问的情况,可通过修改tomcat/conf下的server.xml来实现。具体配置可参考下面这段代码,注意<Service name=”Catalina1″>这个标签中的配置。

?
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
<?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.core.JreMemoryLeakPreventionListener" />
  <Listener className="org.apache.catalina.mbeans.GlobalResourcesLifecycleListener" />
  <Listener className="org.apache.catalina.core.ThreadLocalLeakPreventionListener" />
  <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">
    <!-- 此处使用了ssl配置,需用https才可访问 -->
    <Connector port="8284" protocol="HTTP/1.1"
      connectionTimeout="20000"
      redirectPort="8443" URIEncoding="UTF-8"
      clientAuth="false" sslProtocol="TLS"
      SSLEnabled="true" scheme="https" secure="true"
      keystoreFile="conf/tomcat.jks" keystorePass="pico2012server"
      truststoreFile="conf/tomcat.jks" truststorePass="pico2012server"
      />
    <Connector port="8009" protocol="AJP/1.3" redirectPort="8443" />
 
    <Engine name="Catalina" defaultHost="localhost">
 
      <Realm className="org.apache.catalina.realm.LockOutRealm">
        <Realm className="org.apache.catalina.realm.UserDatabaseRealm"
          resourceName="UserDatabase"/>
      </Realm>
 
      <Host name="localhost" appBase="webapps"
        unpackWARs="true" autoDeploy="true">
        <Valve className="org.apache.catalina.valves.AccessLogValve" directory="logs"
          prefix="localhost_access_log." suffix=".txt"
          pattern="%h %l %u %t &quot;%r&quot; %s %b" />
 
      </Host>
    </Engine>
  </Service>
 
  <!-- 加入一个新的网站服务配置,每个service都可以单独配置工程加载目录、端口等 -->
  <Service name="Catalina1">
    <!-- 此处表示加载的工程仍使用原始的http方式访问 -->
    <Connector port="8484" protocol="HTTP/1.1"
      connectionTimeout="20000"
      redirectPort="8443" URIEncoding="UTF-8"
      />
    <Connector port="18009" protocol="AJP/1.3" redirectPort="18443" />
 
    <Engine name="Catalina1" defaultHost="localhost">
      <Realm className="org.apache.catalina.realm.LockOutRealm">
        <Realm className="org.apache.catalina.realm.UserDatabaseRealm"
          resourceName="UserDatabase"/>
      </Realm>
      <!-- 该service加载的工程放置目录,与webapps同目录的webapps1 -->
      <Host name="localhost" appBase="webapps1"
        unpackWARs="true" autoDeploy="true">
 
        <Valve className="org.apache.catalina.valves.AccessLogValve" directory="logs"
          prefix="localhost_access_log." suffix=".txt"
          pattern="%h %l %u %t &quot;%r&quot; %s %b" />
        <!-- 此处要显示的指定加载webapps1下的GS-Web工程 -->
        <Context path="" docBase="GS-Web" debug="0" reloadable="true"/>
      </Host>
    </Engine>
  </Service>
</Server>

以上就是本文的全部内容,希望对大家的学习有所帮助,也希望大家多多支持服务器之家。

原文链接:http://www.androidchina.net/8029.html

延伸 · 阅读

精彩推荐