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

相关推荐
handsomestWei6 小时前
Docker引擎API接入配置
运维·http·docker·容器·api
汤愈韬11 小时前
网络安全之网络基础知识_2
网络协议·安全·web安全
风逸尘_lz13 小时前
05-LPB3568针对不同网段实现UDP通信
网络·网络协议·udp
灰子学技术15 小时前
Envoy 中 TCP 网络连接实现分析
运维·服务器·网络·网络协议·tcp/ip
IpdataCloud16 小时前
米哈游黑产案解析:游戏账号批量注册如何用IP查询识别外挂与多开用户?操作指南
网络协议·tcp/ip·游戏
星宇笔记16 小时前
我做了一个本地网页版嵌入式调试工具:支持 Serial / TCP / UDP、实时曲线、HEX 发送
单片机·嵌入式硬件·网络协议·tcp/ip·udp·开源软件
请数据别和我作队16 小时前
Python实现直播弹幕数据采集(WebSocket实时弹幕采集)
开发语言·网络·python·websocket·网络协议·学习分享
大數據精準工單獲取16 小时前
【数据抓取】 编写爬虫基本请求:使用爬虫框架发送 HTTP 请求,获取网页内容
爬虫·网络协议·http
测试人社区—835216 小时前
‌TCP/IP协议栈参数调优验证:软件测试从业者指南
网络·人工智能·网络协议·tcp/ip·测试工具·语音识别·压力测试
时空自由民.16 小时前
HTTP协议和MQTT协议区别
网络·网络协议·http