1. 线上的配置

    1. spring:
    2. cloud:
    3. gateway:
    4. routes:
    5. # ws表示websocket的转发
    6. - id: test-websocket
    7. uri: ws://127.0.0.1:9006
    8. predicates:
    9. - Path=/ws/**
    10. filters:
    11. - StripPrefix=1
    12. # ws表示websocket的转发
    13. - id: nocas-websocket
    14. uri: ws://test-websocket
    15. predicates:
    16. - Path=/ser/ws/**
    17. filters:
    18. - StripPrefix=2
    19. - id: api-websocket
    20. uri: lb://test-websocket
    21. predicates:
    22. - Path=/api/**
    23. filters:
    24. - StripPrefix=1
    25. # ws表示websocket的转发
    26. - id: test-websocket2
    27. uri: ws://127.0.0.1:9007
    28. predicates:
    29. - Path=/ws2/**
    30. filters:
    31. - StripPrefix=1
    32. # ws表示websocket的转发 - 这是错误的
    33. - id: nocas-websocket2
    34. uri: ws://test-websocket2
    35. predicates:
    36. - Path=/ser2/ws/**
    37. filters:
    38. - StripPrefix=2
    39. - id: nocas2-websocket2
    40. uri: lb:ws://test-websocket2
    41. predicates:
    42. - Path=/serlb/ws/**
    43. filters:
    44. - StripPrefix=2
    45. - id: api-websocket2
    46. uri: lb://test-websocket2
    47. predicates:
    48. - Path=/api2/**
    49. filters:
    50. - StripPrefix=1
  2. 线下可以的配置 ```yaml server: port: 9005

spring: main: allow-bean-definition-overriding: true

profiles:

active: socket

application: name: gateway cloud: nacos: discovery: server-addr: 127.0.0.1:8848 # 注册中心 group: websocket namespace: f5b7faf1-58b9-4365-b366-3893c470a208 config: server-addr: 127.0.0.1:8848 # 配置中心 namespace: f5b7faf1-58b9-4365-b366-3893c470a208 group: websocket file-extension: yaml #文件扩展名格式,针对于默认的{spring.application.name}-${profile}.${file-extension:properties}配置 enabled: true #开启或关闭配置中心 gateway: discovery: locator: enabled: true # 开启基于服务的注册和发现 的 路由转发,默认轮询模式 globalcors: corsConfigurations: ‘[/*]’: allowedHeaders: ““ allowedOrigins: ““ allowedMethods: “

配置这一项可以监控gateway各个节点的信息

management: endpoints: web: exposure: include: gateway

  1. 3. 线下不可行的配置
  2. ```yaml
  3. server:
  4. port: 9005
  5. spring:
  6. application:
  7. name: test-gateway
  8. cloud:
  9. nacos:
  10. discovery:
  11. server-addr: 127.0.0.1:8848 # 注册中心
  12. group: websocket
  13. namespace: f5b7faf1-58b9-4365-b366-3893c470a208
  14. config:
  15. server-addr: 127.0.0.1:8848 # 配置中心
  16. group: websocket
  17. file-extension: yaml #文件扩展名格式,针对于默认的{spring.application.name}-${profile}.${file-extension:properties}配置
  18. enabled: true #开启或关闭配置中心
  19. namespace: f5b7faf1-58b9-4365-b366-3893c470a208
  20. #路由配置,user-service是我的服务名
  21. gateway:
  22. discovery:
  23. locator:
  24. enabled: true
  25. # lower-case-service-id: true
  26. globalcors:
  27. corsConfigurations:
  28. '[/**]':
  29. allowedHeaders: "*"
  30. allowedOrigins: "*"
  31. allowedMethods: "*"
  32. management:
  33. endpoints:
  34. web:
  35. exposure:
  36. include: gateway
  1. 对比之后发现这个错误真无语
    1. srping.application.name=gateway ( - ) srping.application.name=test-gateway
    2. application.name的名字要跟线上的yaml名字一样。既
      1. image.pngimage.png