如何解决nginx入口中的cor域白名单
我正在尝试向 Kubernetes nginx-ingress 添加域白名单,因此它允许多个域来源。我试过这样的事情:
Nginx.ingress.kubernetes.io/configuration-snippet: |
set $cors '';
if ($http_origin ~ '^https?://(localhost:4000|www\.example.com\.com)$') {
set $cors 'true';
}
# The above is used only if map is not used
# --------------------------------------------------
if ($cors = 'true') {
more_set_headers 'Access-Control-Allow-Origin' "$http_origin" always;
more_set_headers 'Access-Control-Allow-Credentials' 'true' always;
more_set_headers 'Access-Control-Allow-Methods' 'GET,POST,PUT,DELETE,OPTIONS' always;
more_set_headers 'Access-Control-Allow-Headers' 'Accept,Authorization,Cache-Control,Content-Type,DNT,If-Modified-Since,Keep-Alive,Origin,User-Agent,X-Requested-With' always;
# required to be able to read Authorization header in frontend
#more_set_headers 'Access-Control-Expose-Headers' 'Authorization' always;
}
if ($request_method = 'OPTIONS') {
# Tell client that this pre-flight info is valid for 20 days
more_set_headers 'Access-Control-Max-Age' 1728000;
more_set_headers 'Content-Type' 'text/plain charset=UTF-8';
more_set_headers 'Content-Length' 0;
return 204;
}
但我得到一个 net::ERR_HTTP2_PROTOCOL_ERROR,这是解决这个问题的错误方法吗?
版权声明:本文内容由互联网用户自发贡献,该文观点与技术仅代表作者本人。本站仅提供信息存储空间服务,不拥有所有权,不承担相关法律责任。如发现本站有涉嫌侵权/违法违规的内容, 请发送邮件至 dio@foxmail.com 举报,一经查实,本站将立刻删除。