目录
一、跨域请求图解
二、跨域解决方案集
三、nginx配置跨域请求配置
打开config/nginx.conf文件,添加如下:
# 允许跨域请求的域,*代表所有
add_header 'Access-Control-Allow-Origin' *;
# 允许带上cookie请求
add_header 'Access-Control-Allow-Credentials' 'true';
#允许请求的方法,如GET/POST/PUT/DELETE
add_header 'Access-Control-Allow-Methods' *;
#允许请求的header
add_header 'Access-Control-Allow-Headers ' *;
配置完成,刷新服务器
nginx -t
nginx -s reload
ok配置完成!
四、防盗链
对于非该域名下的访问视作非法访问,并返回错误码:
#对源站点验证
valid_referers *.wxl.com;
#非法引入会进入下方判断
if($invalid_referer){
return 404;
}