记一次tomcat、gateway配置SSL,使用https访问

1、前置条件:

外网对应服务器的nginx已配置跳转,并给到了域名对应的ssl相关文件 xxx.pfx 和密码串

前端访问

        http://域名:8081

        解析到: http://IP:8081

后端接口

        http://域名:88

        解析到: http://IP:88

2、服务器配置SSL

        架构使用了前后端分离,所以前后端访问都需要配置SSL

2.1、前端

前端正式环境url访问配置

        https://域名:8081

前端正式环境url调用访问后台配置

        https://域名:88

前端部署在tomcat,tomcat 的conf/server.xml文件配置


<Connector port="8081"
    protocol="org.apache.coyote.http11.Http11NioProtocol"
    SSLEnabled="true"
    scheme="https"
    secure="true"
    keystoreFile="conf/cert/xxx.pfx"
    keystorePass="xxx"
    clientAuth="false"
    SSLProtocol="TLSv1+TLSv1.1+TLSv1.2"
    ciphers="TLS_RSA_WITH_AES_128_CBC_SHA,TLS_RSA_WITH_AES_256_CBC_SHA,TLS_ECDHE_RSA_WITH_AES_128_CBC_SHA,TLS_ECDHE_RSA_WITH_AES_128_CBC_SHA256,TLS_RSA_WITH_AES_128_CBC_SHA256,TLS_RSA_WITH_AES_256_CBC_SHA256"/>

2.2、后端

使用springcloud gateway作为网关

gataway微服务配置

pom.xml添加插件

      

            <plugin>
                <groupId>org.apache.maven.plugins</groupId>
                <artifactId>maven-resources-plugin</artifactId>
                <configuration>
                    <encoding>UTF-8</encoding>
                    <!-- 过滤后缀为pkcs12、jks的证书文件 -->
                    <nonFilteredFileExtensions>
                        <nonFilteredFileExtension>pfx</nonFilteredFileExtension>
                        <nonFilteredFileExtension>jks</nonFilteredFileExtension>
                    </nonFilteredFileExtensions>
                </configuration>
            </plugin>

配置文件bootstrap.yml配置

         

server:
  port: 88
  ssl:
    key-store: classpath:xxx.com.pfx
    key-store-type: PKCS12
    enabled: true
    key-store-password: xxx

配置文件application.yml配置(每个微服务都配置)   uri: lb:http://微服务名称

        - id: xxx_route
          uri: lb:http://微服务名称
          predicates:
            #- Host=域名
            - Path=/api/**
          filters:
            - RewritePath=/api/(?<segment>.*),/$\{segment}