首页
学习
活动
专区
圈层
工具
发布
社区首页 >问答首页 >如何在nginx中子域名访问域名?

如何在nginx中子域名访问域名?
EN

Stack Overflow用户
提问于 2018-05-15 04:01:59
回答 1查看 1.4K关注 0票数 0

使用nginx,我在需要从example.com获取其json数据的sub.example.com上提供了一个html文件

但是没有加载json。相反,在Chrome浏览器中,我得到:

代码语言:javascript
复制
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.

我该如何解决这个问题呢?

EN

回答 1

Stack Overflow用户

发布于 2018-05-16 04:59:45

您需要在您的example.com服务器上设置CORS headers,以允许域sub.example.com使用此资源,例如:

访问-控制-允许-来源

代码语言:javascript
复制
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;

代码语言:javascript
复制
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中允许*,但不建议这样做。

票数 0
EN
页面原文内容由Stack Overflow提供。腾讯云小微IT领域专用引擎提供翻译支持
原文链接:

https://stackoverflow.com/questions/50338148

复制
相关文章

相似问题

领券
问题归档专栏文章快讯文章归档关键词归档开发者手册归档开发者手册 Section 归档