✅ 操作成功!

Nginx解决跨域问题No ‘Access

发布时间:2023-06-17 作者:admin 来源:文学

Nginx解决跨域问题No ‘Access

Nginx解决跨域问题No ‘Access

浏览器控制台报错

Access to XMLHttpRequest at ‘www.aaa’ from Origin ‘www.bbb’ has been blocked by CORS policy: No ‘Access-Control-Allow-Origin’ header is present on the requested resource.

解决办法

使用Nginx在server块下或location块下为请求添加请求头都可以解决跨域问题。

add_header 'Access-Control-Allow-Origin' '*'; add_header 'Access-Control-Allow-Methods' 'GET,POST,DELETE'; add_header 'Access-Control-Allow-Header' 'Content-Type,*';

👁️ 阅读量:0