nginx cors跨域配置多域名问题
桃小天 2018-07-12 02:48:29 本人nginx小白文一些nginx配置跨域的问题
看网上好多人的配置都这么写的 贴下代码 搞不明白 $http_origin哪来的 怎么配置的 是内置变量吗 应该怎么配置多域名
location /pub/(.+) {
if ($http_origin ~ <允许的域(正则匹配)>) {
add_header 'Access-Control-Allow-Origin' "$http_origin";
add_header 'Access-Control-Allow-Credentials' "true";
if ($request_method = "OPTIONS") {
add_header 'Access-Control-Max-Age' 86400;
add_header 'Access-Control-Allow-Methods' 'GET, POST, OPTIONS, DELETE';
add_header 'Access-Control-Allow-Headers' 'reqid, nid, host, x-real-ip, x-forwarded-ip, event-type, event-id, accept, content-type';
add_header 'Content-Length' 0;
add_header 'Content-Type' 'text/plain, charset=utf-8';
return 204;
}
}
# 正常nginx配置
......
}