记录一次解决跨域问题解决过程。 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;
#}
# }
最后一位大佬的博客给了我思路

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

浙公网安备 33010602011771号