记录一次解决跨域问题解决过程。 strict-origin-when-cross-origin,net::ERR_FAILED, No 'Access-Control-Allow-Origin' header is present on the requested resource.
1.Unable to import Maven project项目无法运行的错误2.记录基于docker部署的禅道用nginx代理出错的问题3.记录docker中ngnix配置文件路由的问题4.前端传输json数据,后端如何用枚举接受5.记录一次分页查询第一页和第二页数据重复问题6.解决mysql出现docker出现access denied for user root@% to database“xxx”的问题7.解决Failed to configure a DataSource: ‘url‘ attribute is not specified and no embedded datasource数据源无法连接 springboot项目无法启动的问题8.Method com/mysql/jdbc/JDBC4ResultSet.getObject(Ljava/lang/String;Ljava/lang/Class;)Ljava/lang/Objec9.mybatis-plus加入日志输出,并且不打印结果集row只输出sql10.解决mysql自动插入的日期时间和现在的时间不一致的问题(基于docker)11.mysql数据库自动删除12.解决docker中gitlab的ssh拉取代码需要密码异常的问题13.记录解决HttpServletResponse在参数报错的问题14.自定义异常以及统一处理自定义返回值
15.记录一次解决跨域问题解决过程。 strict-origin-when-cross-origin,net::ERR_FAILED, No 'Access-Control-Allow-Origin' header is present on the requested resource.
事情是这样的,vue项目本地启动可以正常连接后端端口访问,部署到nginx上只有就无法访问,显示跨域问题
于是查看后端日志
啥都没有,觉得肯定是nginx的问题,怎么配置都没用,
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 | 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的原因的话加个注解就解决了