vue+springboot前后端分离项目中配置https

首先前端,vue打包后生成了dist,使用tomcat作为静态服务器,在tomcat中使用jks格式配置https(不是jks可以不用往下看了):

  • 将文件拷贝到tomcat的conf目录,修改server.xml(注意修改jks和密码那里):
     <Connector port="443" protocol="org.apache.coyote.http11.Http11NioProtocol" maxThreads="150" SSLEnabled="true">
        <SSLHostConfig>
            <Certificate certificateKeystoreFile="conf/cdc.com.jks" certificateKeystorePassword="602tsfe" type="RSA"/>
        SSLHostConfig>
    Connector>
  • 将下面加载web.xml最后面,不用修改任何东西:
<login-config>
        
        <auth-method>CLIENT-CERTauth-method>
        <realm-name>Client Cert Users-only Arearealm-name>
    login-config>
    <security-constraint>
        
        <web-resource-collection >
            <web-resource-name >SSLweb-resource-name>
            <url-pattern>/*url-pattern>
        web-resource-collection>
        <user-data-constraint>
            <transport-guarantee>CONFIDENTIALtransport-guarantee>
        user-data-constraint>
    security-constraint>
  • springboot 配置https:
  • 首先将jks文件拷贝到classpath下(resources目录下)。
  • 然后在application.properties中添加:
# 配置https:
server.ssl.key-store=classpath:cd.com.jks
server.ssl.key-store-password=60fe
server.ssl.key-store-type=JKS
  • 然后配置http跳转https(请注意通过properties配置只能使用https或者http,不能同时使用https和http):
    算了不配了,能用就行。

你可能感兴趣的:(vue.js,spring,boot,https)