问题:

        最近前端获取音频的波形报了个错:

Access to audio at 'http://xxx/03.wav' from origin 'http://zzz' has been blocked by CORS policy: The 'Access-Control-Allow-Origin' header contains multiple values 'zzz, *', but only one is allowed. 

        很奇怪的是这个文件直接用地址能访问正常,项目中直接访问也正常,而在项目中请求波形中就报错,另一个minio中的文件就能正常访问

分析:

  1. 多了一个跨域设置的源 Access-Control-Allow-Origin
  2. 不能访问的文件的地址通过nginx转过端口

        项目的后端是做了跨域处理的(第一个Access-Control-Allow-Origin) ,然后请求文件转地址nginx也做了跨域处理(第二个Access-Control-Allow-Origin)

解决问题:

        修改nginx的配置文件,单独隐藏其nginx的跨域处理

    server {
        listen       1300;
        server_name  localhost;
		client_max_body_size 10M;

		autoindex    on;
        #charset koi8-r;

        access_log  logs/host.access.log;
		add_header Access-Control-Allow-Origin *;
		add_header Access-Control-Allow-Methods 'GET, POST, OPTIONS';
		add_header Access-Control-Allow-Headers 'DNT,X-Mx-ReqToken,Keep-Alive,User-Agent,X-Requested-With,If-Modified-Since,Cache-Control,Content-Type,Authorization,cookietoken,cookieuid,lang';

        location / {
            root   html;
            index  index.html index.htm;
						
        }
		
		location /upload/ {
			alias D:/minio/;
		}
		location /upload/sub/ {
			proxy_pass http://xxx:2000/;
			#proxy_set_header Host $host:$server_port;
			proxy_hide_header Access-Control-Allow-Origin;
			proxy_hide_header Access-Control-Allow-Methods;
			proxy_hide_header Access-Control-Allow-Headers;
		}
    }

proxy_hide_header Access-Control-Allow-Origin;
proxy_hide_header Access-Control-Allow-Methods;
proxy_hide_header Access-Control-Allow-Headers; 

Logo

北京人形旗下天工造物具身智能开源社区,聚焦具身天工与慧思开物两大平台

更多推荐