详细的错误信息
生产环境页面控制台报错某些接口访问504
Access to fetch at 'https://server.xxx.xxx.cn/xxx/xxx/xxx' from origin 'https://xxx.xxx.cn' has been blocked by CORS policy: No 'Access-Control-Allow-Origin' header is present on the requested resource. If an opaque response serves your needs, set the request's mode to 'no-cors' to fetch the resource with CORS disabled.
umi.4d7fa049.js:834 POST https://server.xxx.xxx.cn/xxx/xxx/xxx net::ERR_FAILED 504
排查思路
1.一开始看到CORS以为是跨域超时了,后来看了SpringSecurity跨域配置,默认时长都是1800s pass
2.查到有控制异步请求的超时配置如下:
spring.mvc.async.request-timeout=2000
可是我这是同步请求 pass
3.还有可能是tomcat默认的超时配置 但是本地一样的内置tomcat没进行任何配置无法复现,说明不是内置tomcat的问题
4.最后发现报错的后端地址链接上不带端口,说明是被代理过了,这也是为什么我在测试环境无法复现的原因
问题复现
nginx代理后端服务 并且前后端部署不可在同一台机器,否则报错和这个不一样
nginx 路由添加如下的三个timeout
location /xxx {
proxy_pass http://localhost:xxxx/xxx;
proxy_connect_timeout 18;
#这三个timeout的单位是秒
proxy_send_timeout 18;
proxy_read_timeout 18;
}
修改措施
1.修改这三个timeout修改至接口所需时长
2.优化接口响应时间