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

相关推荐
hhh123987_1 小时前
以太网基础⑥ ZYNQ PS端 基于LWIP的TCP例程测试
网络·网络协议·tcp/ip
Lfsd1 小时前
根据ip获取地址库
网络·网络协议·tcp/ip
喵手5 小时前
Java 11 新特性:从模块化到 HTTP/2 深度解析
java·开发语言·http
GOATLong6 小时前
传输层协议TCP
c语言·开发语言·网络·c++·网络协议·tcp/ip
DemonAvenger8 小时前
HTTP/2在Go中的实现与优化
网络协议·架构·go
程序员良辰8 小时前
URL与URI:互联网世界的“门牌号“与“身份证“
java·网络协议
摘星编程8 小时前
MCP协议深度解析:客户端-服务器架构的技术创新
网络协议·技术创新·系统架构设计·mcp协议·客户端服务器架构
游戏开发爱好者81 天前
没有 Mac,如何上架 iOS App?多项目复用与流程标准化实战分享
android·ios·小程序·https·uni-app·iphone·webview
bksheng1 天前
【SSL证书校验问题】通过 monkey-patch 关掉 SSL 证书校验
网络·爬虫·python·网络协议·ssl
mykyle1 天前
Canal 1.1.7的安装
网络协议·tcp/ip·adb