如何在没有重定向的情况下在Tomcat中启用HTTP和HTTPS?

时间:2017-01-24 04:21:12

标签: tomcat

我正在配置Tomcat以支持HTTP(在端口8080上)和HTTPS(端口8443)。在server.xml中,如果我这样配置:

    <Connector port="8080" protocol="HTTP/1.1"
           connectionTimeout="20000"
           URIEncoding="UTF-8" 
           redirectPort="8443" />

    <Connector port="8443" protocol="HTTP/1.1" 
           SSLEnabled="true"
           scheme="https" 
           secure="true"
           Server=""
           keystoreFile="conf/.keystore"
           keystorePass="password"
           maxThreads="150"
           maxSpareThreads="75"
           minSpareThreads="25" 
           clientAuth="false" sslProtocol="TLS" 
           URIEncoding="UTF-8"
           />

http://SERVER_IP:8080的所有访问都将定向到https://SERVER_IP:8443。如何禁用重定向,并允许http和https访问?

我尝试删除redirectPort="8443",但它不起作用。

1 个答案:

答案 0 :(得分:5)

在@pedrofb的帮助下,我找到了解决方案:除了修改server.xml文件外,编辑web.xml文件,如:

<security-constraint>
    <web-resource-collection>
    <web-resource-name>Support Both HTTP and HTTPS
    </web-resource-name>
    <url-pattern>/*</url-pattern>
    </web-resource-collection>
    <user-data-constraint>
      <!-- <transport-guarantee>CONFIDENTIAL</transport-guarantee> -->
    </user-data-constraint>
</security-constraint>

确保注释<transport-guarantee>CONFIDENTIAL</transport-guarantee>,否则它只允许HTTPS访问。