server {
location / {
add_header 'Access-Control-Allow-Origin' '*';
}
}
server {
location / {
add_header 'Access-Control-Allow-Origin' '*';
add_header 'Access-Control-Request-Method' 'GET';
}
}
server {
location / {
# 白名单
if ($http_origin ~* (baidu\.com|github.xuexb.com)$) {
add_header 'Access-Control-Allow-Origin' '$http_origin';
# 允许cookie
add_header 'Access-Control-Allow-Credentials' true;
# 只允许某些方法
add_header 'Access-Control-Request-Method' 'GET, POST, OPTIONS';
# 支持获取其她字段, 需要前端设置 `xhr.withCredentials = true`
add_header 'Access-Control-Allow-Headers' 'User-Agent,X-Requested-With,If-Modified-Since,Cache-Control,Content-Type';
}
}
}