记录一次解决跨域问题解决过程。 strict-origin-when-cross-origin,net::ERR_FAILED, No 'Access-Control-Allow-Origin' header is present on the requested resource.

事情是这样的,vue项目本地启动可以正常连接后端端口访问,部署到nginx上只有就无法访问,显示跨域问题

 

 于是查看后端日志

 啥都没有,觉得肯定是nginx的问题,怎么配置都没用,

	location / {
		root   html;
		index  index.html index.htm;
		add_header 'Access-Control-Allow-Origin' '*';
        add_header 'Access-Control-Allow-Methods' 'GET, POST, OPTIONS';
        add_header 'Access-Control-Allow-Headers' 'DNT,User-Agent,X-Requested-With,If-Modified-Since,Cache-Control,Content-Type,Range';
        add_header 'Access-Control-Expose-Headers' 'Content-Length,Content-Range';

        }
        #location /data/ {
		#proxy_pass http://localhost;
		#proxy_set_header X-Real-IP $remote_addr;
		#proxy_set_header X-Forwarded-For $proxy_add_x_forwarded_for;
		#add_header Access-Control-Allow-Origin *;
		#add_header Access-Control-Allow-Methods GET,POST,OPTIONS;
		#add_header Access-Control-Allow-Headers X-Requested-With;
		#add_header Access-Control-Max-Age 60000;
		#add_header Access-Control-Allow-Credentials true;
		#if ( $request_method = OPTIONS ){
		#	return 200;
		#}
	    # }

  

最后一位大佬的博客给了我思路

高质量搬砖工人必会——Vue利用axios发起ajax请求遇到的问题(been blocked by CORS policy:;Failed to load resource: net::ERR_F)_axios.min.js:1 failed to load resource: net::err_q-CSDN博客

 如果是springboot的原因的话加个注解就解决了

 

posted @ 2024-04-03 12:08  绿茶汤圆  阅读(1721)  评论(0)    收藏  举报