nginx跨域报40x,50x等错误时,跨域不成功
需要在add_header Access-Control-Allow-...
后面添加 always
参数,如下:
add_header Access-Control-Allow-Origin '$http_origin' always;
add_header Access-Control-Allow-Credentials 'true' always;
add_header Access-Control-Allow-Headers 'Pragma,DNT,X-Mx-ReqToken,Keep-Alive,User-Agent,X-Requested-With,If-Modified-Since,Cache-Control,Content-Type,Authorization' always;
add_header Access-Control-Allow-Methods 'GET,POST,OPTIONS,DELETE,PATCH,PUT' always;
if ($request_method = 'OPTIONS') {
return 204;
}