Nginx跨域

##CROS跨域资源共享

  • Cross-Origin Resource Sharing
  • 允许浏览器向跨Origin的服务器发起js请求获取响应
  • Jsonp、SpringBoot Cors、Nginx

在Nginx配置跨域

在Nginx.conf配置文件的Server块内配置如下内容:

server {
    ...
    #允许跨域请求的域,*代表所有
    add_header 'Access-Control-Allow-Origin' *;
    #允许带上Cookie请求
    add_header 'Access-Control-Allow-Credentials' 'true';
    #允许请求的方法,比如 GET/POST/PUT/DELETE
    add_header 'Access-Control-Allow-Methods' *;
    #允许请求的header
    add_header 'Access-Control-Allow-Headers' *;
    ...
}