Nginx支持Vue跨域
在location /{} 中添加
add_header Access-Control-Allow-Origin $http_origin; add_header Access-Control-Allow-Methods 'GET, POST, OPTIONS,PUT,DELETE'; add_header Access-Control-Allow-Headers 'DNT,X-Mx-ReqToken,Keep-Alive,User-Agent,X-Requested-With,If-Modified-Since,Cache-Control,Content-Type,Authorization,token'; if ($request_method = 'OPTIONS') { return 204; }
由于新版Chrome不允许将 Origin头设置为*,所以改为$http_origin,实现动态获取路径并且返回。