需要在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;
}