美文网首页
CORS nginx 添加跨域

CORS nginx 添加跨域

作者: peerben | 来源:发表于2021-02-24 13:18 被阅读0次
location / {
        if (-f $document_root/deployment) {
            return 503;
        }

        if ($request_method = 'OPTIONS') {
          add_header 'Access-Control-Allow-Origin' '*';
          add_header 'Access-Control-Allow-Credentials' 'true';
          add_header 'Access-Control-Allow-Headers' 'motivatedBy, content-type, Authorization, contentlanguage, displayLanguage, Access-Control-Allow-Origin';
          add_header 'Access-Control-Allow-Methods' 'GET,POST,OPTIONS,PUT,DELETE,PATCH';
          add_header 'Access-Control-Expose-Headers' 'Location';
          add_header 'Access-Control-Max-Age' 1728000;
          add_header 'Content-Type' 'text/plain charset=UTF-8';
          add_header 'Content-Length' 0;
          return 204;
        }

        add_header 'Access-Control-Allow-Origin' '*';
        add_header 'Access-Control-Allow-Credentials' 'true';
        add_header 'Access-Control-Allow-Headers' 'Accept-Encoding, Accept-Language, Authorization,Accept,Origin,DNT,X-Chisel-Proxied-Url,Keep-Alive,User-Agent,X-Requested-With,If-Modified-Since,Cache-Control,Content-Type,Content-Range,Range';
        add_header 'Access-Control-Allow-Methods' 'GET,POST,OPTIONS,PUT,DELETE,PATCH';

        proxy_set_header X-Forwarded-For $proxy_add_x_forwarded_for;
        proxy_set_header Host $host;
        proxy_set_header X-Real-IP $remote_addr;

        proxy_max_temp_file_size 0;
        proxy_buffering off;
        proxy_connect_timeout 30;
        proxy_send_timeout 30;
        proxy_read_timeout 1200;
        proxy_pass http://cluster_kubernetes_workers;
        proxy_redirect https://xx:30081/ https://xx/;
    }
}

相关文章

网友评论

      本文标题:CORS nginx 添加跨域

      本文链接:https://www.haomeiwen.com/subject/hehsfltx.html