nginx配置图片跨域访问

在server段中添加红框内的图片跨域内容

参数

location ~* .*\.(gif|jpg|jpeg|png|bmp|swf)$ {
add_header Access-Control-Allow-Origin *;
add_header Access-Control-Allow-Headers X-Requested-With;
add_header Access-Control-Allow-Methods GET,POST,PUT,DELETE,OPTIONS;

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

拓展

这种的就是图片文件都支持跨域,将要跨域的在location匹配就行。

 

posted @ 2020-12-18 11:42  點燈的人  阅读(4220)  评论(0编辑  收藏  举报