tomcat配置https访问

配置https:

vim /usr/local/tomcat/conf/server.xml
# http配置:
    <Connector port="8080" protocol="HTTP/1.1"
               connectionTimeout="20000"
               redirectPort="8443"
               maxParameterCount="1000"
               scheme="http"
               secure="false"
               />
# https配置:
    <Connector port="8443" protocol="org.apache.coyote.http11.Http11NioProtocol"
               maxThreads="150" SSLEnabled="true"
               maxParameterCount="1000"
               scheme="https"
               secure="true"
               >
        <SSLHostConfig>
            <Certificate certificateKeystoreFile="/usr/local/tomcat/ssl/ruoyibackend.zqfstack.com.pfx"
                         certificateKeystorePassword="1qaz@WSX" type="RSA" />
        </SSLHostConfig>
    </Connector>

# certificateKeystoreFile= 填写证书地址
# certificateKeystorePassword= 填写生成证书时的密码

配置强制跳转https:

vim /usr/local/tomcat/conf/web.xml
# 在</welcome-file-list>下面添加:
    <security-constraint>
        <web-resource-collection>
            <web-resource-name>HTTPS Only</web-resource-name>
            <url-pattern>/*</url-pattern>  <!-- 匹配所有路径 -->
        </web-resource-collection>
        <user-data-constraint>
            <transport-guarantee>CONFIDENTIAL</transport-guarantee>  <!-- 强制使用 HTTPS -->
        </user-data-constraint>
    </security-constraint>

之后重启tomcat访问即可。

posted @ 2025-08-15 12:33  阿峰博客站  阅读(12)  评论(0)    收藏  举报