zoukankan      html  css  js  c++  java
  • zuul路由网关集成ssl,实现http到https的转变

    1 前言

      最近几天刚开始接触微信小程序的开发,才接触到了https的概念(微信小程序中的请求必须为https请求,不然请求无法成功)。https算是对http的安全封装,在http的基础上加了ssl证书机制,此处不赘述,想要详细了解自行百度区别。所以博主就在考虑怎么让整个小程序后台(用的spring boot来作为后台)都能通过https访问,终于经过两天的研究,我发现了将ssl结合spring cloud的zuul(路由网关)可以实现我想要的效果,话不多说,上步骤。

    2 申请域名,并用域名申请ssl证书(博主用的阿里申请的ssl证书)

    点击下载,将对应的ssl证书下载到本地

    3 创建zuul微服务

      3.1pom.xml中配置相关依赖(需要添加到eureka注册中心)

         <dependency>
                <groupId>org.springframework.cloud</groupId>
                <artifactId>spring-cloud-starter-netflix-eureka-client</artifactId>
            </dependency>
            <dependency>
                <groupId>org.springframework.cloud</groupId>
                <artifactId>spring-cloud-starter-netflix-zuul</artifactId>
            </dependency>

      3.2 将ssl证书放到resources下的ssl文件夹中并在yml中配置

    spring:
      application:
        name: zuul
    #注册到eureka
    eureka:
      instance:
        lease-expiration-duration-in-seconds: 30
        lease-renewal-interval-in-seconds: 10
        prefer-ip-address: true
        instance-id: dragon
      client:
        fetch-registry: true
        register-with-eureka: true
        service-url:
          defaultZone: http://localhost:7001/eureka/
    server:
      port: 443
    #  ssl证书相关配置
      ssl:
        key-store: classpath:https/1538502410793.pfx
        key-store-password: 1538502410793
        key-store-type: PKCS12
    #zuul的相关配置
    zuul:
      routes:
    #    需要配置路由的微服务
        consumer:
          serviceId: eureka-consumer
          path: /con/**
    #      无法使用服务名称访问
      ignored-services: "*"
    #  访问前添加前缀
      prefix: /fengyuntec/

      注意:https的默认端口为443,这里也建议设置成443

       3.3 在zuul微服务的启动类上添加注解

    @SpringBootApplication
    @EnableZuulProxy
    public class ZuulApplication {
        public static void main(String[] args) {
            SpringApplication.run(ZuulApplication.class, args);
        }
    }

    4 访问网址

      4.1 访问http://localhost:7001/ 进入eureka注册中心查看服务

      4.2 访问网址 https://www.dragonchen.top/fengyuntec/con/hello

    5 总结

    1508952532 博主qq,有什么问题可以问我,愿程序员的世界一片祥和。

  • 相关阅读:
    Spring常见面试题
    Mybatis常见面试题
    SQLSERVER查询整个数据库中某个特定值所在的表和字段的方法
    四款常见数据库比较同步软件汇总
    SQL Server常用函数整理
    比较经典的SQL面试题
    sqlserver查询数据库中有多少个表
    数据库设计三大范式
    MS SQL SERVER导出表结构到Excel
    flask-vue 解决跨域问题
  • 原文地址:https://www.cnblogs.com/cl-rr/p/9713896.html
Copyright © 2011-2022 走看看