Tomcat配置https

下载证书文件可获得 Tomcat 文件夹,其中有密钥库 www.domain.com.jks。

证书安装

配置SSL连接器,将 www.domain.com.jks 文件存放到 conf 目录下,然后配置同目录下的 server.xml 文件:

 <Connector port="443" protocol="HTTP/1.1" SSLEnabled="true"
    maxThreads="150" scheme="https" secure="true"
    keystoreFile="conf/www.domain.com.jks"
    keystorePass="changeit"
    clientAuth="false" sslProtocol="TLS" />

HTTP自动跳转HTTPS的安全配置

找到 conf 目录下的 web.xml 文件, 在该文件的 下面,添加以下内容:

 <login-config>
    <!-- Authorization setting for SSL -->
    <auth-method>CLIENT-CERT</auth-method>
    <realm-name>Client Cert Users-only Area</realm-name>
    </login-config>
    <security-constraint>
    <!-- Authorization setting for SSL -->
    <web-resource-collection>
    <web-resource-name>SSL</web-resource-name>
    <url-pattern>/*</url-pattern>
    </web-resource-collection>
    <user-data-constraint>
    <transport-guarantee>CONFIDENTIAL</transport-guarantee>
    </user-data-constraint>
    </security-constraint>

为了让非 SSL 的 connector 可以跳转到 SSL 的 connector 中,还需要前往 server.xml 进行配置:

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

redirectPort 改成 SSL 的 connector 的端口443,重启后便会生效。

原文地址:https://www.cnblogs.com/manastudent/p/12264279.html