繁体   English   中英

如何允许从Nginx中的子域访问域?

[英]How to allow access to domain from subdomain in nginx?

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

但是未加载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.

我怎样才能解决这个问题?

您需要在example.com服务器上设置CORS标头,以允许域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中允许*,但不建议使用。

暂无
暂无

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM