美文网首页
Nginx 跨域配置

Nginx 跨域配置

作者: IOwl | 来源:发表于2018-11-15 16:42 被阅读0次

1、在nginx.conf文件http里配置

    add_header Access-Control-Allow-Origin *;
    add_header Access-Control-Allow-Credentials true;
    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;

2、在(有多个项目配置的)具体的项目配置里location /里

if ($request_method = 'OPTIONS') {
    add_header Access-Control-Allow-Origin *;
    add_header Access-Control-Allow-Methods GET,POST,OPTIONS;
    add_header Access-Control-Allow-Credentials true;
    add_header Access-Control-Allow-Headers DNT,X-CustomHeader,Keep-Alive,User-Agent,X-Requested-With,If-Modified-Since,Cache-Control,Content-Type;
    return 204;
}

相关文章

网友评论

      本文标题:Nginx 跨域配置

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