Nginx跨域无法访问,通常报错:

Failed to load http://172.18.6.30:8086/CityServlet: No 'Access-Control-Allow-Origin' header is present on the requested resource. Origin 'http://test.dingkailinux.cn' is therefore not allowed access.

可以在nginx的配置文件中对应的localtion中添加:

           add_header Access-Control-Allow-Origin *; #"*"表示允许所有域名,可以替换成你允许的域名
           add_header 'Access-Control-Allow-Credentials' 'true';
           add_header 'Access-Control-Allow-Headers' 'Authorization,Content-Type,Accept,Origin,User-Agent,DNT,Cache-Control,X-Mx-ReqToken,X-Requested-With';
           add_header 'Access-Control-Allow-Methods' 'GET,POST,OPTIONS';

重启nginx,就可以访问了

相关文章:

  • 2021-06-07
  • 2021-06-13
  • 2022-02-14
  • 2021-11-16
  • 2022-12-23
猜你喜欢
  • 2022-12-23
  • 2022-12-23
  • 2021-11-01
  • 2021-10-03
相关资源
相似解决方案