nginx跨域配置

2020-12-03  本文已影响0人  稀饭52

使用场景

跨域配置

  1. 打开根目录下的conf/nginx.conf文件

  2. 在server配置跨域转发处理


  location / {
      root   html;
      index  index.html index.htm;
      proxy_pass yuming.com; #需要访问的接口域名
  }
  add_header Access-Control-Allow-Origin *; #设置跨域域名
  add_header Access-Control-Allow-Credentials true; #携带cookie

  if ( $request_method = 'OPTIONS' ) { #拦截options请求
      return 200;
  }

  #使用`http://localhost/接口地址`访问

nginx常用命令

上一篇 下一篇

猜你喜欢

热点阅读