栏目分类:
子分类:
返回
名师互学网用户登录
快速导航关闭
当前搜索
当前分类
子分类
实用工具
热门搜索
名师互学网 > IT > 软件开发 > 后端开发 > Java

eureka+configserver+gateway集群使用https/http2

Java 更新时间: 发布时间: IT归档 最新发布 模块sitemap 名妆网 法律咨询 聚返吧 英语巴士网 伯小乐 网商动力

eureka+configserver+gateway集群使用https/http2

介绍

本文介绍spring cloud 集群配置https 。
ssl证书的生成这里就不再赘述,网上有一大堆。

集群成员

eureka:注册中心
configserver:配置中心
gateway:网关
其他server

配置

eureka:

server:
  port: 8761
  http2:
    enabled: true
  ssl:
    enabled: true
    #证书配置
    key-store-password: ****
    key-store-type: PKCS12
    key-store: classpath:****.pfx
eureka:
  client:
    register-with-eureka: false
    fetch-registry: false
    service-url:
      default-zone: https://${eureka.instance.hostname}:${server.port}/eureka/
  instance:
    hostname: localhost
    # 重要配置
    securePortEnabled: true
    nonSecurePortEnabled: false

configserver:

eureka:
  client:
    service-url:
      defaultZone: https://localhost或者域名:8761/eureka/
  instance:
  	# 使用ip的方式访问configserver
    prefer-ip-address: true
    # 不开启安全端口
    #securePortEnabled: true

configserver这里我们不开启https的形式访问,如果开启的话,服务的配置需要指定:

spring.config.uri =  https://域名:8888

这样就无法使用注册中心发现服务。
如果configserver开启https形式访问,其他服务使用注册中心发现配置中心服务的话,服务启动时会报错:

No subject alternative names matching IP address xxxx found

gateway:

server:
  port: 8443
  http2:
    enabled: true
  ssl:
    enabled: true
    #证书配置
    key-store-password: ****
    key-store-type: PKCS12
    key-store: classpath:****.pfx
spring:
  application:
    name: gateway
  cloud:
    config:
      discovery:
        enabled: true
      fail-fast: true
      # 使用https形式访问配置中心,若配置中心配置了https 不使用此方式无法访问
      #uri:https://域名:端口
    gateway:
      httpclient:
        ssl:
          # 信任下游证书
          use-insecure-trust-manager: true
eureka:
  client:
    service-url:
      defaultZone: https://localhost或者域名:8761/eureka/
  instance:
  	# 开启安全端口,告诉其他服务我的端口是https访问方式
    securePortEnabled: true
    prefer-ip-address: true

注意:如果不使用http2 可将server.http2.enabled 配置去掉

spring cloud 2021.0.0 才开始支持使用http2
http2 需在支持https的前提下使用

转载请注明:文章转载自 www.mshxw.com
本文地址:https://www.mshxw.com/it/918959.html
我们一直用心在做
关于我们 文章归档 网站地图 联系我们

版权所有 (c)2021-2022 MSHXW.COM

ICP备案号:晋ICP备2021003244-6号