您的位置:首页 > 运维架构 > Nginx

使用nginx配置跨域的案例

2017-11-22 00:37 711 查看
server {
listen       80;
server_name  grafana.test.com;
#charset koi8-r;
#access_log  logs/host.access.log  main;
location / {
auth_basic            "Restricted";
auth_basic_user_file  /opt/graphite/grafana/htpasswd/pass;
if ($http_origin ~* (http://[^/]*\.test\.com)){
set $cors "true";
}
if ($cors = 'true') {
add_header  Access-Control-Allow-Origin $http_origin;
add_header Access-Control-Allow-Headers X-Requested-With;
add_header  "Access-Control-Allow-Credentials" "true";
add_header  "Access-Control-Allow-Methods" "GET, POST, OPTIONS";
add_header  "Access-Control-Allow-Headers" "Authorization, origin, accept";
}
root /opt/graphite/grafana;
}
}
内容来自用户分享和网络整理,不保证内容的准确性,如有侵权内容,可联系管理员处理 点击这里给我发消息
标签: