解决:Spring Cloud微服务的Zuul网关发请求出现504错误

写短信验证功能点击发送验证码,前台写的ajax.then..catch,弹出了一个请求状态504,后台zuulexception

504错误代表网关超时,是指服务器作为网关或代理,没有及时从上游服务器接收到请求

正常情况下,是由于被请求服务器发送超时引起。

解决方法:只需在网关的配置里面,负载均衡超时等待时间

原来yml配置文件

#端口号
server:
  port: 10010

#服务名
spring:
  application:
    name: cgzuul
  servlet:
    multipart:
      max-file-size: 2MB    #上传文件的大小
#将网关服务添加到注册中心
eureka:
  client:
    fetch-registry: true
    register-with-eureka: true
    service-url:
      defaultZone: http://127.0.0.1:10086/eureka
  instance:
    prefer-ip-address: true
#网关统一配置 --  访问路径 http://localhost:10010/v3/服务名/路径
zuul:
  prefix: /v3
  sensitive-headers: Cookie,Set-Cookie

新增ribbon配置

#端口号
server:
  port: 10010

#服务名
spring:
  application:
    name: cgzuul
  servlet:
    multipart:
      max-file-size: 2MB    #上传文件的大小
#将网关服务添加到注册中心
eureka:
  client:
    fetch-registry: true
    register-with-eureka: true
    service-url:
      defaultZone: http://127.0.0.1:10086/eureka
  instance:
    prefer-ip-address: true
#网关统一配置 --  访问路径 http://localhost:10010/v3/服务名/路径
zuul:
  prefix: /v3
  sensitive-headers: Cookie,Set-Cookie
#解决504方案  
ribbon:
  ReadTimeout: 120000  #请求处理的超时时间
  ConnectTimeout: 30000  #请求连接的超时时间

  • 0
    点赞
  • 3
    收藏
    觉得还不错? 一键收藏
  • 2
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论 2
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值