spring cloud gateway 实现https

编程入门 行业动态 更新时间:2024-10-05 23:21:52

spring <a href=https://www.elefans.com/category/jswz/34/1771354.html style=cloud gateway 实现https"/>

spring cloud gateway 实现https

spring cloud gateway 实现https

一、windows安装openssl

.html

二、配置环境变量

在环境变量path中加入openssl的安装路径下的bin包

三、查看是否正确安装

进入命令行 输入openssl看有无输出即可

四、创建自签名证书

进入cmd命令行操作,生成文件路径默认为当前cmd命令路径(用户根目录)

0)格式说明

实际上自签名证书的所有格式都是pem格式,但是我们为它命名为不同的后缀是为了便于区分

  • .key 为密钥
  • .csr 为证书申请文件
  • .crt 为证书
1)生成私钥
openssl genrsa -out root_private.key 1024
# 下面这个是生成有密码的私钥
openssl genrsa -des3 -out CA/root.key 1024

1024为密钥长度

2)生成公钥
openss lrsa -in root_private.key -pubout -out root_public.key
3)使用密钥生成证书申请文件
openssl req -new -out root.csr -key root_private.key
4)生成自签名证书
openssl x509 -req -in root.csr -out root.crt -signkey root_private.key -days 3650

标记生成3650天

5)将证书格式改成浏览器常用的p12格式
openssl pkcs12 -export -clcerts -in root.crt -inkey root_private.key -out root.p12 -name "root"

-name为设置别名

五、配置spring cloud gateway

官网信息

server:ssl:enabled: truekey-alias: scg # 别名key-store-password: scg1234 # 密码key-store: classpath:scg-keystore.p12 # 位置key-store-type: PKCS12 # 类型

六、问题排查

1)SSLHandshakeException: no cipher suites in common

没有共同的密码套件,这个时候需要考虑两种情况

  • 服务端和客户端的tls版本不对
  • 服务端压根就没放证书

对于第一种情况,在服务端可以查看自己的证书信息看一下tls版本是多少,在客户端(浏览器)可以进入开发者模式查看security,如果使用了https那里会显示tls的版本

对于第二种情况,则需要检查是否真正在服务端放置好了数字签名证书

我出现的情况是,我以为找到了,但是实际上并没有

我配置的签名没有设置别名,但是我在配置文件中设置它的别名为空,导致了错误,但是并没有报错

server:ssl:enabled: truekey-alias: key-store-password: ky_envkey-store: classpath:ky_env.keystorekey-store-type: PKCS12

所以如果没有设置别名的,把alias这一行删除掉即可

2)前端调用接口无反应

后端会收到如下消息,则表示,使用了https加密的方式,但是是用http来链接。

17:49:31.056 [reactor-http-nio-3] ERROR reactorty.tcp.TcpServer  - [id: 0x6991a8d2, L:0.0.0.0/0.0.0.0:8080 ! R:/0:0:0:0:0:0:0:1:62338] onUncaughtException(SimpleConnection{channel=[id: 0x6991a8d2, L:0.0.0.0/0.0.0.0:8080 ! R:/0:0:0:0:0:0:0:1:62338]})
ioty.handler.codec.DecoderException: ioty.handler.ssl.NotSslRecordException: not an SSL/TLS record: ...

更多推荐

spring cloud gateway 实现https

本文发布于:2024-02-28 10:48:27,感谢您对本站的认可!
本文链接:https://www.elefans.com/category/jswz/34/1769495.html
版权声明:本站内容均来自互联网,仅供演示用,请勿用于商业和其他非法用途。如果侵犯了您的权益请与我们联系,我们将在24小时内删除。
本文标签:cloud   spring   https   gateway

发布评论

评论列表 (有 0 条评论)
草根站长

>www.elefans.com

编程频道|电子爱好者 - 技术资讯及电子产品介绍!