【问题标题】:How to disable HTTPS on tomcat and have it run on port 8080?如何在 tomcat 上禁用 HTTPS 并让它在端口 8080 上运行?
【发布时间】:2021-04-16 16:34:41
【问题描述】:

我的 server.xml 中有以下连接器。我的应用程序在端口 8080 上运行,我不再希望它在端口 8443 上运行。如何修改连接器以禁用 HTTPS 并且只在 8080 上运行 tomcat?谢谢

    <!--
    <Connector port="8080" protocol="HTTP/1.1"
               connectionTimeout="20000"
               redirectPort="8443" />
    -->
    <!-- Define a SSL/TLS HTTP/1.1 Connector on port 8443
         This connector uses the NIO implementation that requires the JSSE
         style configuration. When using the APR/native implementation, the
         OpenSSL style configuration is required as described in the APR/native
         documentation -->
    <!--
    <Connector port="8443" protocol="org.apache.coyote.http11.Http11NioProtocol"
               maxThreads="150" SSLEnabled="true" scheme="https" secure="true"
               clientAuth="false" sslProtocol="TLS" />
    -->
    <Connector port="8443" protocol="HTTP/1.1"
               SSLEnabled="true" maxThreads="150" scheme="https" secure="true"
               keystoreFile="tomcat.keystore" keystorePass="changeit" sslEnabledProtocols="TLSv1.1,TLSv1.2"
               ciphers="TLS_RSA_WITH_AES_128_GCM_SHA256,TLS_ECDH_ECDSA_WITH_AES_128_GCM_SHA256"/>

【问题讨论】:

  • 已经尝试启用第一个和禁用最后一个Connector

标签: http tomcat server.xml


【解决方案1】:

你需要一个Connector:

<Connector port="8080" protocol="HTTP/1.1"
           connectionTimeout="20000" />

并注释掉您的端口 8443 连接器。

这将侦听关闭端口(在您的 Server 节中定义,默认为 8005)和端口 8080。但是请注意,如果客户端代码想要升级到 HTTPS,它将失败,因为您不再拥有 redirectPort

【讨论】:

  • 你怎么知道OP的实际关闭端口在8005上?
  • redirectPort 的默认值实际上是 443,(至少因为 Tomcat 7)。要禁用重定向端口,您需要将其显式设置为 0 或更小(参见source code)。假设 -1.
  • @PiotrP.Karwasz - 但是分发的 server.xml 有 8443,因此它可以在 Unix 环境中无需 root 运行。这是来自 Tomcat 9。我已经验证删除 redirectPort 不会创建任何其他端口,lsof 在 LISTEN 中仅显示两个端口。
  • 我同意监听端口的数量,但我不同意“如果客户端代码要升级到HTTPS,它会失败......”。如果指定了&lt;security-constraint&gt;,Tomcat 会将客户端重定向到端口443。如果您设置redirectPort="-1",Tomcat 将立即发出403 HTTP 错误。
【解决方案2】:

从您的原始代码中可以看出,请取消注释 port="8080" 部分并注释掉 port="8443" 部分如下,

请注意redirectPort="8443"的含义在here987654321@的详细解释

enter image description here

【讨论】:

    【解决方案3】:
    This will work
    
      
        <Connector port="8080" protocol="HTTP/1.1"
                   connectionTimeout="20000"
                   redirectPort="8443" />
        
        <!-- Define a SSL/TLS HTTP/1.1 Connector on port 8443
             This connector uses the NIO implementation that requires the JSSE
             style configuration. When using the APR/native implementation, the
             OpenSSL style configuration is required as described in the APR/native
             documentation -->
        <!--
        <Connector port="8443" protocol="org.apache.coyote.http11.Http11NioProtocol"
                   maxThreads="150" SSLEnabled="true" scheme="https" secure="true"
                   clientAuth="false" sslProtocol="TLS" />
        -->
    <!--
        <Connector port="8443" protocol="HTTP/1.1"
                   SSLEnabled="true" maxThreads="150" scheme="https" secure="true"
                   keystoreFile="tomcat.keystore" keystorePass="changeit" sslEnabledProtocols="TLSv1.1,TLSv1.2"
                   ciphers="TLS_RSA_WITH_AES_128_GCM_SHA256,TLS_ECDH_ECDSA_WITH_AES_128_GCM_SHA256"/>
    -->
    

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 2014-08-14
      • 1970-01-01
      • 2011-04-03
      • 2013-08-29
      • 2019-12-23
      • 2019-05-27
      • 2015-02-24
      • 2017-10-13
      相关资源
      最近更新 更多