Nginx跨域配置 和 防盗链配置

  • 在nginx.conf中server中配置
#跨域配置:
#允许跨域请求的域,*代表所有
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' *;

#防盗链配置
#对源站点验证,*.imooc.com代表允许域名imooc.com下的站点访问
valid_referers *.imooc.com代表允许域名;
#非法引入会进入下方判断
if ($invalid_referer) {
    return 404;
}
posted @ 2021-08-26 23:06  金盛年华  阅读(49)  评论(0编辑  收藏  举报