簡體   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