Nginx跨域问题

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,就可以访问了

猜你喜欢

转载自www.cnblogs.com/dingkailinux/p/9179242.html