Nginx 解决跨域问题

Nginx 解决跨域问题

Cross-Origin Resource Sharing

nginx.conf 文件中的具体server块中添加如下内容

http {

  server {
    
    listen 80;
    server_name localhost;
  
  	#允许跨域请求的域,*代表所有 
    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' *;
  }

}

版权声明:本文为weixin_43740223原创文章,遵循CC 4.0 BY-SA版权协议,转载请附上原文出处链接和本声明。