nginx 处理跨域以及 OPTIONS预检请求

在 server中加入一下代码
#跨域处理
add_header Access-Control-Allow-Origin *;
add_header Access-Control-Allow-Headers X-Requested-With,Content-Type,language;
add_header Access-Control-Allow-Methods GET,POST,OPTIONS;
add_header Access-Control-Allow-Credentials true;

#预检请求处理
if ($request_method ~* OPTIONS|DELETE) {
    return 200;
}

 

posted @ 2022-04-29 11:28  pengcx  阅读(898)  评论(0编辑  收藏  举报