当前位置: 移动技术网 > 网络运营>服务器>nginx > Nginx跨域设置Access-Control-Allow-Origin无效的解决办法

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

2019年04月17日  | 移动技术网网络运营  | 我要评论

电脑娃娃演员表,毛小平简历,你最珍贵伴奏

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/plain charset=utf-8';
        add_header 'content-length' 0;
        return 204;
       }
       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';
       }

总结

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

如对本文有疑问,请在下面进行留言讨论,广大热心网友会与你互动!! 点击进行留言回复

相关文章:

验证码:
移动技术网