服务端解决跨域问题的方案(二)

一分钟说明

本文主要基于Nginx的配置来解决服务端跨域问题。
涉及知识点:
- Nginx的配置

  • Nginx的跨域配置
location /project {
        proxy_pass http://10.10.10.10:8080/project;
        proxy_set_header Host $host;
        proxy_set_header X-Real-IP $remote_addr;
        add_header 'Access-Control-Allow-Origin' '*'; //跨域允许的域名
        add_header 'Access-Control-Allow-Credentials' 'true'; //跨域是否带上cookie信息
        add_header 'Access-Control-Allow-Methods' 'GET'; //跨域允许的请求方式
}

然后重启nginx服务就可以生效了

service nginx restart

猜你喜欢

转载自blog.csdn.net/luoliang2012/article/details/78274422
今日推荐