springboot服务或者gateway网关将http改为https

1.去阿里云服务器,搜索ssl证书,免费申请
2.下载证书

因为是springboot服务,所以使用Tomcat或者JKS(JDK支持的类型)

3.配置

server:

ssl:

enable: true

key-store: classpath: 自定义ssl证书文件

key-store-type: PKCS12

key-store-password: 阿里云下载证书对应密码

4.证书放在resources目录下,maven打包是会报异常.com.pfx failed with MalformedInputException: Input length = 1

两种方式

4.1 使用 maven-resources-plugin 进行过滤
java 复制代码
            <plugin>
                <groupId>org.apache.maven.plugins</groupId>
                <artifactId>maven-resources-plugin</artifactId>
                <configuration>
                    <!-- 过滤后缀为jks(或者pfx)的证书文件 -->
                    <nonFilteredFileExtensions>
                        <nonFilteredFileExtension>jks(或者pfx)</nonFilteredFileExtension>
                    </nonFilteredFileExtensions>
                </configuration>
            </plugin>
4.2 使用 resources 进行过滤
java 复制代码
        <resources>
            <resource>
            //将资源文件中的除了后缀为 jks(或者pfx) 的其他文件打包到classpath下,对文件做处理
                <directory>src/main/resources</directory>
                <filtering>true</filtering>
                <excludes>
                    <exclude>*.jks(或者pfx)</exclude>
                </excludes>
            </resource>

            <resource>
            //将资源文件中后缀为 jks(或者pfx) 的文件打包到classpath,但不对文件做处理
                <directory>src/main/resources</directory>
                <filtering>false</filtering>
                <includes>
                    <include>*.jks(或者pfx)</include>
                </includes>
            </resource>
        </resources>

5.如果是gateway服务需要设置后台微服务访问方式

因为进来时是https请求,在gateway转发给其他微服务时依然是https请求,这时可通过将其他服务也设置成https访问,即每个服务都进行配置ssl,同时采用域名进行注册服务,比较麻烦,改为转发时为http服务

spring:

cloud:

gateway:

routes: #配置路由路径

  • id: xx-server

之前路由为 uri: lb://xx-server

uri: lb:http://xx-server

相关推荐
微硬创新1 小时前
不用换设备,也能接入智能系统:耐达讯自动化NY-B801网关的神奇功效
人工智能·网络协议·自动化·信息与通信
__zRainy__2 小时前
Node系列 · Node基础:https 模块
后端·网络协议·http·https·node.js
SeaTunnel3 小时前
从 JSON 到 JSONL,Apache SeaTunnel 如何解决HTTP 大数据传输的内存难题?
http·开源·json·apache·数据集成·seatunnel
80s77713 小时前
住宅代理解析:动态住宅IP与静态住宅IP如何选型?
网络·网络协议·tcp/ip
略略略咯咯17 小时前
网络协议-study
网络·网络协议
DLYSB_17 小时前
从监控告警到现场处置:用 HTTP API、Modbus TCP 构建声光语音告警系统
网络协议·tcp/ip·http·报警灯
爱学习的程序媛18 小时前
通信协议完整梳理
网络·网络协议·信息与通信·通信协议
佳児素花痴╮19 小时前
服务器模型、网络调试工具、网络协议头分析
服务器·网络·网络协议
阿pin19 小时前
TCP VS UDP
网络协议·tcp/ip·udp
treesforest20 小时前
信贷反欺诈实战:通过IP属地一致性核验识别虚假贷款申请
网络协议·tcp/ip·php