nginx 跨域

server {    
   listen       xx;
   server_name  xxxxxx.com;

   location / {
       proxy_pass http://localhost:1234/;
   }
   
      add_header Access-Control-Allow-Origin *;
      add_header Access-Control-Allow-Headers Authorization,Content-Type,Accept,Origin,User-Agent,DNT,Cache-Control,X-Mx-ReqToken,X-Data-Type,X-Requested-With,token,platform;
      add_header Access-Control-Allow-Methods GET,POST,OPTIONS,HEAD,PUT;
      add_header Access-Control-Allow-Credentials true;
 
      proxy_set_header x-real-ip $remote_addr;
      proxy_set_header X-Forwarded-For $proxy_add_x_forwarded_for;

      if ( $request_method = 'OPTIONS' ) { 
            return 200;
       }

   access_log /var/log/nginx/api-access.log;
   error_log  /var/log/nginx/api-error.log;

}

你可能感兴趣的:(nginx 跨域)