线上的配置
spring:
cloud:
gateway:
routes:
# ws表示websocket的转发
- id: test-websocket
uri: ws://127.0.0.1:9006
predicates:
- Path=/ws/**
filters:
- StripPrefix=1
# ws表示websocket的转发
- id: nocas-websocket
uri: ws://test-websocket
predicates:
- Path=/ser/ws/**
filters:
- StripPrefix=2
- id: api-websocket
uri: lb://test-websocket
predicates:
- Path=/api/**
filters:
- StripPrefix=1
# ws表示websocket的转发
- id: test-websocket2
uri: ws://127.0.0.1:9007
predicates:
- Path=/ws2/**
filters:
- StripPrefix=1
# ws表示websocket的转发 - 这是错误的
- id: nocas-websocket2
uri: ws://test-websocket2
predicates:
- Path=/ser2/ws/**
filters:
- StripPrefix=2
- id: nocas2-websocket2
uri: lb:ws://test-websocket2
predicates:
- Path=/serlb/ws/**
filters:
- StripPrefix=2
- id: api-websocket2
uri: lb://test-websocket2
predicates:
- Path=/api2/**
filters:
- StripPrefix=1
线下可以的配置 ```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
3. 线下不可行的配置
```yaml
server:
port: 9005
spring:
application:
name: test-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 # 配置中心
group: websocket
file-extension: yaml #文件扩展名格式,针对于默认的{spring.application.name}-${profile}.${file-extension:properties}配置
enabled: true #开启或关闭配置中心
namespace: f5b7faf1-58b9-4365-b366-3893c470a208
#路由配置,user-service是我的服务名
gateway:
discovery:
locator:
enabled: true
# lower-case-service-id: true
globalcors:
corsConfigurations:
'[/**]':
allowedHeaders: "*"
allowedOrigins: "*"
allowedMethods: "*"
management:
endpoints:
web:
exposure:
include: gateway
- 对比之后发现这个错误真无语
- srping.application.name=gateway ( - ) srping.application.name=test-gateway
- application.name的名字要跟线上的yaml名字一样。既