location / {
# 處理跨域問題 start
# 允許請求地址跨域 * 做為通配符
add_header 'Access-Control-Allow-Origin' '*';
# 設置請求方法跨域
add_header 'Access-Control-Allow-Methods' 'GET, POST, OPTIONS, PUT, DELETE';
# 設置是否允許 cookie 傳輸
add_header 'Access-Control-Allow-Credentials' 'true';
# 設置請求頭 這里為什么不設置通配符 * 因為不支持
add_header 'Access-Control-Allow-Headers' 'token,Authorization,Content-Type,Accept,Origin,User-Agent,DNT,Cache-Control,X-Mx-ReqToken,X-Data-Type,X-Requested-With,X-Data-Type,X-Auth-Token';
# 設置 options 請求處理
if ( $request_method = 'OPTIONS' ) {
return 200;
}
# 處理跨域問題 end
#下面略略略
}
重啟!完畢!