背景
按照W3C的标准,增加了默认的请求头后会触发复杂请求,即OPTIONS 请求资源是否可以访问,如果不做处理服务器会默认返回405错误;需要返回200才能继续发起正常请求;参考配置如下。
nginx 复杂请求配置(options请求405错误)
location /api{
if ($request_method = 'OPTIONS') {
add_header Access-Control-Allow-Origin *;
add_header Access-Control-Allow-Credentials true;
add_header Access-Control-Allow-Methods 'GET, POST, OPTIONS';
add_header Access-Control-Allow-Headers 'withcredentials,xx-api-version,xx-device-type,xx-token';
return 200;
}}
}