Nginx跨域设置Access-Control-Allow-Origin无效的解决办法
nginx版本1.11.3
使用大家说的以下配置,验证无效,跨域问题仍然存在
add_header'Access-Control-Allow-Origin''*'; add_header'Access-Control-Allow-Credentials''true'; add_header'Access-Control-Allow-Methods''GET,POST';
使用以下配置,生效。
if($request_method='OPTIONS'){
add_header'Access-Control-Allow-Origin''*';
add_header'Access-Control-Allow-Methods''GET,POST,OPTIONS';
add_header'Access-Control-Allow-Headers''DNT,X-CustomHeader,Keep-Alive,User-Agent,X-Requested-With,If-Modified-Since,Cache-Control,Content-Type';
add_header'Access-Control-Max-Age'1728000;
add_header'Content-Type''text/plaincharset=UTF-8';
add_header'Content-Length'0;
return204;
}
if($request_method='POST'){
add_header'Access-Control-Allow-Origin''*';
add_header'Access-Control-Allow-Methods''GET,POST,OPTIONS';
add_header'Access-Control-Allow-Headers''DNT,X-CustomHeader,Keep-Alive,User-Agent,X-Requested-With,If-Modified-Since,Cache-Control,Content-Type';
}
if($request_method='GET'){
add_header'Access-Control-Allow-Origin''*';
add_header'Access-Control-Allow-Methods''GET,POST,OPTIONS';
add_header'Access-Control-Allow-Headers''DNT,X-CustomHeader,Keep-Alive,User-Agent,X-Requested-With,If-Modified-Since,Cache-Control,Content-Type';
}
总结
以上就是这篇文章的全部内容了,希望本文的内容对大家的学习或者工作具有一定的参考学习价值,谢谢大家对毛票票的支持。如果你想了解更多相关内容请查看下面相关链接
热门推荐
1 泰迪狗狗如何训练
3 狗狗训练图
5 狗狗训练方法
6 训练狗狗不咬人
8 敏捷训练狗狗
10 训练狗狗吃饭
11 泰迪狗狗训练
12 狗狗从多大开始训练
13 狗狗训练学校费用
14 怎么去训练狗狗
15 狗狗训练狗狗
16 狗狗训练教程
17 训练狗狗装死
18 泰迪狗狗的训练方法