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

相关推荐
liubaoyi21734 分钟前
网络原理--HTTP
网络·http
聪明努力的积极向上3 小时前
【C#】HTTP中URL编码方式解析
开发语言·http·c#
平凡而伟大(心之所向)4 小时前
TCP Socket(TCP 套接字)和 WebSocket 区别详解
websocket·网络协议·tcp/ip
huangql5204 小时前
HTTP协议与WebSocket完整技术指南
websocket·网络协议·http
Rysxt_7 小时前
UDP请求解析教程:深入理解请求头、请求体与参数机制
网络·网络协议·udp
2501_916008897 小时前
前端工具全景实战指南,从开发到调试的效率闭环
android·前端·小程序·https·uni-app·iphone·webview
小马哥编程8 小时前
JWT 是由哪三个部分组成?如何使用JWT进行身份认证?
网络协议·http·架构·ssh
noravinsc8 小时前
https 可以访问 8866端口吗
网络协议·http·https
Unstoppable228 小时前
八股训练营第 6 天 | HTTPS 和HTTP 有哪些区别?HTTPS的工作原理(HTTPS建立连接的过程)?TCP和UDP的区别?
tcp/ip·http·https·八股
称心-如意8 小时前
浅谈TCP与UDP协议:TCP和UDP分别是什么,区别在哪里
网络协议·tcp/ip·udp