0
点赞
收藏
分享

微信扫一扫

Nginx指定多个域名跨域配置

yongxinz 03-19 11:00 阅读 3

server {
        set $cors '';
        if ($http_origin ~* "^http://deomain01$") {
            set $cors $http_origin;
        }
        if ($http_origin ~* "^http://deomain02$") {
            set $cors $http_origin;
        }
        if ($http_origin ~* "^http://deomain03$") {
            set $cors $http_origin;
        }
        location /live {
                  ...
                add_header 'Access-Control-Allow-Origin' '$cors';
                #不带cookie请求,设置为false
                add_header 'Access-Control-Allow-Credentials' 'true';
                # 为预检请求加的header,允许跨域的方法
                add_header 'Access-Control-Allow-Methods' 'GET, POST, PUT, DELETE';
                #为预检请求加的header,允许跨域使用的请求头
                add_header 'Access-Control-Allow-Headers' '*';
        }

举报

相关推荐

0 条评论