使用nginx,我在需要从example.com获取其json数据的sub.example.com上提供了一个html文件
但是没有加载json。相反,在Chrome浏览器中,我得到:
The 'Access-Control-Allow-Origin' header has a value 'https://example.com' that is not equal to the supplied origin. Origin 'http://sub.example.com' is therefore not allowed access.我该如何解决这个问题呢?
发布于 2018-05-16 04:59:45
您需要在您的example.com服务器上设置CORS headers,以允许域sub.example.com使用此资源,例如:
访问-控制-允许-来源
add_header Access-Control-Allow-Origin "https://sub.example.com" always;
add_header Access-Control-Allow-Headers "Origin, Content-Type, Accept" always;
add_header Access-Control-Allow-Methods "GET, POST, PUT, OPTIONS, DELETE" always;或
add_header Access-Control-Allow-Origin "https://*.example.com" always;
add_header Access-Control-Allow-Headers "Origin, Content-Type, Accept" always;
add_header Access-Control-Allow-Methods "GET, POST, PUT, OPTIONS, DELETE" always;您需要在处理Json的服务器中设置它。您可以在CORS中允许*,但不建议这样做。
https://stackoverflow.com/questions/50338148
复制相似问题