zxpnet网站 zxpnet网站
首页
前端
后端服务器
  • 分类
  • 标签
  • 归档
GitHub (opens new window)

zxpnet

一个爱学习的java开发攻城狮
首页
前端
后端服务器
  • 分类
  • 标签
  • 归档
GitHub (opens new window)
  • 大后端课程视频归档
  • 南航面试题
  • 并发编程

  • 性能调优

  • java8语法

  • lombok

  • 日志

  • 工具类

  • spring

  • mybatis

  • springboot

  • redis

  • zookeeper

  • springcloud

    • springcloud开源项目
    • nacos

    • eureka

    • openfeign

    • gateway网关

      • springcloud gateway基础
        • gateway基础
        • 集成nacos
          • 引入starter
          • 写配置
      • Zuul网关安全开发
    • zipkin链路追踪

    • sentinel

    • seata

    • TX-LCN

  • dubbo

  • netty

  • springsecurity

  • mq消息中间件

  • shiro

  • beetle

  • 模板引擎

  • jpa

  • 数据结构与算法

  • 数据库知识与设计

  • gradle

  • maven

  • bus

  • 定时任务

  • docker

  • centos

  • 加解密

  • biz业务

  • pigx项目

  • 开源项目

  • 品达通用权限项目-黑马

  • 货币交易项目coin-尚学堂

  • php

  • backend
  • springcloud
  • gateway网关
shollin
2021-07-18
目录

springcloud gateway基础

  • gateway基础
  • 集成nacos
    • 引入starter
    • 写配置

# gateway基础

# 集成nacos

# 引入starter

<!-- nacos starter -->
<dependency>
	<groupId>com.alibaba.cloud</groupId>
	<artifactId>spring-cloud-starter-alibaba-nacos-discovery</artifactId>
</dependency>
<dependency>
	<groupId>com.alibaba.cloud</groupId>
	<artifactId>spring-cloud-starter-alibaba-nacos-config</artifactId>
</dependency>

<dependency>
    <groupId>org.springframework.cloud</groupId>
    <artifactId>spring-cloud-starter-gateway</artifactId>
</dependency>
<!--客户端负载均衡loadbalancer-->
<dependency>
	<groupId>org.springframework.cloud</groupId>
	<artifactId>spring-cloud-starter-loadbalancer</artifactId>
</dependency>
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19

image-20210804155857939

从starter的依赖中可以看到,从springcloud2020弃用了Ribbon,因此需要再引入Ribbon的jar包,否则无法通过lb路由到指定微服务,出现了503情况。

# 写配置

spring:
  cloud:
    gateway:
      discovery:
        locator:
          enabled: true # 根据服务名称从注册中心获取服务请求地址
          lower-case-service-id: true  #使用小写服务名,默认是大写

      routes:
        - id: baidu-proxy
          uri: https://www.163.com/
          predicates:
            - Path=/163

        - id: url-proxy-1 #保持唯一
          uri: https://blog.csdn.net
          predicates:
            - Path=/csdn

        - id: oauth2AuthServer # 路由 ID,唯一
          uri: lb://oauth2-auth-server # 根据服务名称从注册中心获取服务请求地址
          predicates: # 断言(判断条件)
            - Path=/auth/**      # 匹配对应 URL 的请求,将匹配到的请求追加在目标 URI 之后
          filters:
            - StripPrefix=1

        - id: oauth2ResouceServer
          uri: lb://oauth2-resource-server
          predicates:
            - Path=/client/**
          filters:
            #- StripPrefix=1
            - RewritePath=/client/(?<segment>/?.*), /$\{segment}
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33

参考文章:

Spring Cloud Gateway3官方文档 (opens new window)

openfeign基础
Zuul网关安全开发

← openfeign基础 Zuul网关安全开发→

最近更新
01
国际象棋
09-15
02
成语
09-15
03
自然拼读
09-15
更多文章>
Theme by Vdoing | Copyright © 2019-2023 zxpnet | 粤ICP备14079330号-1
  • 跟随系统
  • 浅色模式
  • 深色模式
  • 阅读模式