美文网首页前端开发小册
ajax 跨域问题 nginx 解决方法

ajax 跨域问题 nginx 解决方法

作者: 国服最坑开发 | 来源:发表于2020-03-06 16:51 被阅读0次

当然可以在api服务层处理, 不过, 在nginx来应该是最方便的解决办法了

location / {  
    add_header Access-Control-Allow-Origin *;
    add_header Access-Control-Allow-Methods 'GET, POST, OPTIONS';
    add_header Access-Control-Allow-Headers 'DNT,X-Mx-ReqToken,Keep-Alive,User-Agent,X-Requested-With,If-Modified-Since,Cache-Control,Content-Type,Authorization';

    if ($request_method = 'OPTIONS') {
        return 204;
    }
} 

相关文章

网友评论

    本文标题:ajax 跨域问题 nginx 解决方法

    本文链接:https://www.haomeiwen.com/subject/yflwrhtx.html