Apache-2.2

Apache/Wordpress 的 CORS 問題

  • August 20, 2014

我在 Apache 中啟用了 CORS,以下是我在載入網站時看到的標題:

HTTP/1.1 200 OK
Access-Control-Allow-Methods: GET, POST, OPTIONS
Access-Control-Allow-Origin: *
Cache-Control: no-cache, must-revalidate, max-age=0, max-age=0, no-cache
Content-Encoding: gzip
Content-Type: text/html; charset=UTF-8
Date: Wed, 20 Aug 2014 17:05:00 GMT
Expires: Wed, 11 Jan 1984 05:00:00 GMT
Link: <http://test.example.com/?p=7>; rel=shortlink
Pragma: no-cache
Server: Apache
Vary: Accept-Encoding
X-Frame-Options: SAMEORIGIN
X-Mod-Pagespeed: 1.7.30.4-
X-Pingback: http://test.example.com/xmlrpc.php
X-Powered-By: PHP/5.4.28
Content-Length: 6757
Connection: keep-alive

但是,當我重新載入頁面時,我收到以下 JS 錯誤:

Cross-Origin Request Blocked: The Same Origin Policy disallows reading the remote resource at http://api.example.com/?x=1. This can be fixed by moving the resource to the same domain or enabling CORS.

任何想法為什麼這會失敗?我正在嘗試從 test.example.com 訪問 api.example.com

我必須將配置添加到我從中請求數據的伺服器中。

引用自:https://serverfault.com/questions/622823