ingress添加annotations
常规配置
在 ingress 的yaml文件中,或者 rancher页面配置
nginx.ingress.kubernetes.io/cors-allow-headers: '*'
nginx.ingress.kubernetes.io/cors-allow-methods: '*'
nginx.ingress.kubernetes.io/cors-allow-origin: '*'
nginx.ingress.kubernetes.io/enable-cors: 'true'
如果http请求种带header
如果是header有自定义字段,则需要指定cors-allow-headers,否则依然会报跨域。例如加入了mytoken字段
报错信息
Access to fetch at xxx from origin xxx has been blocked by CORS policy: Request header field mytoken is not allowed by Access-Control-Allow-Headers in preflight response.

测试代码
<!DOCTYPE html>
<html>
<

博客主要围绕ingress添加annotations展开。介绍了常规配置可在ingress的yaml文件或rancher页面进行。当http请求带header且有自定义字段时会报跨域,给出了报错信息,并提供测试代码,解决方法是指定cors-allow-headers,不能用*。
最低0.47元/天 解锁文章
1190

被折叠的 条评论
为什么被折叠?



