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匹配就行。

原文地址:https://www.cnblogs.com/sxshaolong/p/14154107.html