nginx解决跨域问题配置

只需在nginx的配置文件中的http配置项中加上

add_header Access-Control-Allow-Origin *;
add_header Access-Control-Allow-Headers X-Requested-With;
add_header Access-Control-Allow-Methods GET,POST,OPTIONS;

 ps: allow-headers 有很多值比如:Content-Type等,可以自行添加

ps:https://mp.weixin.qq.com/s/vU-ejo9efh2qHXYqcK7VxQ

 

ps:踩坑记录-前端请求如果携带Cookie信息(withCredentials : true),那么后端Access-Control-Allow-Origin不能为*

posted @ 2022-03-02 09:53  pengcx  阅读(380)  评论(0编辑  收藏  举报