美文网首页
ajax跨域之nginx反向代理

ajax跨域之nginx反向代理

作者: ozil_oo | 来源:发表于2018-08-22 17:11 被阅读0次

    只需在nginx.conf中添加三行代码

      add_header Access-Control-Allow-Origin *;
      add_header Access-Control-Allow-Headers X-Requested-With;
      add_header Access-Control-Allow-Methods GET,POST,OPTIONS;
    

    如果不做反向代理,在响应头中加入跨域允许,以PHP为例

    header('content-type:application:json;charset=utf8');  
    header('Access-Control-Allow-Origin:*');  
    header('Access-Control-Allow-Methods:POST');  
    header('Access-Control-Allow-Headers:x-requested-with,content-type');  
    

    相关文章

      网友评论

          本文标题:ajax跨域之nginx反向代理

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