nginx奇奇怪怪的跨域问题,报错“Response to preflight request doesn't pass access control check: It does not have HTTP ok status”


0,最近迁移了CDN,有几个域名就出现了这样的跨域报错。

20200923171634390.png


1, 解决办法,在出现跨域问题的虚拟主机里加入下面代码

1
2
3
4
5
6
7
8
9
10
11
12
13
14
location / {
......
if ($request_method = OPTIONS ) {
add_header Access-Control-Allow-Origin "*";
add_header Access-Control-Allow-Methods "POST, GET, PUT, OPTIONS, DELETE";
add_header Access-Control-Max-Age "3600";
add_header Access-Control-Allow-Headers "Origin, X-Requested-With, Content-Type, Accept, Authorization";
add_header Access-Control-Allow-Credentials "true";
add_header Content-Length 0;
add_header Content-Type text/plain;
return 200;
}
......
nginx -t && nginx -s reload

2,问题解决