Nginx跨域设置Access-Control-Allow-Origin无效的解决办法

  

nginx版本1.11.3

  

使用大家说的以下配置,验证无效,跨域问题仍然存在

        add_header‘Access-Control-Allow-Origin’‘*’;   add_header Access-Control-Allow-Credentials的“真正的”;   add_header ' Access-Control-Allow-Methods ' GET、POST的;      

使用以下配置,生效。

        if ($ request_method='选项'){   add_header‘Access-Control-Allow-Origin’‘*’;   add_header Access-Control-Allow-Methods”“GET、POST、选项”;   add_header”Access-Control-Allow-Headers‘DNT、X-CustomHeader维生,用户代理,X-Requested-With, if - modified - since, cache - control,内容类型”;   add_header ' Access-Control-Max-Age ' 1728000;   add_header“内容类型”的文本/纯charset=utf - 8 ';   add_header内容长度的0;   返回204;   }   if ($ request_method=癙OST”) {   add_header‘Access-Control-Allow-Origin’‘*’;   add_header Access-Control-Allow-Methods”“GET、POST、选项”;   add_header”Access-Control-Allow-Headers‘DNT、X-CustomHeader维生,用户代理,X-Requested-With, if - modified - since, cache - control,内容类型”;   }   if ($ request_method=暗玫健?{   add_header‘Access-Control-Allow-Origin’‘*’;   add_header Access-Control-Allow-Methods”“GET、POST、选项”;   add_header”Access-Control-Allow-Headers‘DNT、X-CustomHeader维生,用户代理,X-Requested-With, if - modified - since, cache - control,内容类型”;   }      

<强>总结

  

以上就是这篇文章的全部内容了,希望本文的内容对大家的学习或者工作具有一定的参考学习价值,谢谢大家对的支持。如果你想了解更多相关内容请查看下面相关链接

Nginx跨域设置Access-Control-Allow-Origin无效的解决办法