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

相关推荐
文章永久免费只为良心12 小时前
一站式综合查询工具:IP、企业信息与网络空间资产高效查询工具
网络·网络协议·tcp/ip
麻辣长颈鹿Sir13 小时前
TCP/IP四层架构通俗理解及功能介绍
网络协议·tcp/ip·tcp/ip协议四层架构·网络通信介绍
yanlou23314 小时前
[C++/Linux HTTP项目] HTTP服务器基于muduo高性能服务器搭载【深入详解】
运维·服务器·http·muduo库·http高性能服务器
2501_9159184114 小时前
HTTPS 代理失效,启用双向认证(mTLS)的 iOS 应用网络怎么抓包调试
android·网络·ios·小程序·https·uni-app·iphone
北京耐用通信15 小时前
极简部署,稳定通信:耐达讯自动化Profibus光纤链路模块赋能物流自动化喷码效率提升
人工智能·物联网·网络协议·自动化·信息与通信
..过云雨16 小时前
从寻址到转发:网络层 IP 协议全流程工作原理详解
网络·网络协议·tcp/ip
不许哈哈哈16 小时前
HTTP协议基础(运维开发面试版)
http·面试·运维开发
王锋(oxwangfeng)17 小时前
Nginx 四层 TCP 与七层 HTTP 转发实战指南
tcp/ip·nginx·http
2501_9151063217 小时前
混合应用(Hybrid)安全加固,不依赖源码对成品 IPA 混淆
android·安全·小程序·https·uni-app·iphone·webview
酣大智17 小时前
参考模型--传输层
网络·网络协议·tcp/ip