我正在配置 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"
,但它不起作用。
最佳答案
在@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 访问。
关于tomcat - 如何在没有重定向的情况下在 Tomcat 中同时启用 HTTP 和 HTTPS?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/41819962/