Nginx和CORS

xiaoxiao2021-02-28  127

nginx跨域配置,如下配置需要添加到location节点下,要注意options请求可能可能会被分配到的location节点

Access-Control-Allow-Methods中配置的方法要大写

#对于非简单请求

if ($request_method = 'OPTIONS') {             add_header 'Access-Control-Allow-Origin' '*';             add_header 'Access-Control-Allow-Methods' 'DELETE,POST';             add_header 'Access-Control-Allow-Headers' '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;

}

#对于简单请求,一般就是get add_header 'Access-Control-Allow-Origin' '*';

转载请注明原文地址: https://www.6miu.com/read-19774.html

最新回复(0)