2016-04-28 150 views
0

我正在使用elasticsearch的2.3.2版本。在我的elasticsearch.yml文件中,我添加了以下幾行以允許跨源請求。elasticsearch:儘管配置http模塊,跨源請求被阻止

http.cors.enabled: true 
http.cors.allow-credentials: true 
http.cors.allow-methods: OPTIONS,HEAD,GET,POST,PUT,DELETE 
http.cors.max-age: 0 
http.cors.allow-origin: /http?:\/\/localhost(:[0-9]+)?/ 
http.cors.allow-headers : X-Requested-With,X-Auth-Token,Content-Type,Content-Length 

但是,當我嘗試從Firefox執行查詢時,出現以下錯誤;

Cross-Origin Request Blocked: The Same Origin Policy disallows reading the remote 
resource at http://localhost:9200/someIndex/_search?size=10&from=0. 
(Reason: CORS header 'Access-Control-Allow-Origin' missing). 

更換​​參數與"*",似乎工作,但文件表明,這是一個安全的請求。

來自瀏覽器的請求標題如下;

Accept - application/json, text/plain, */* 
Accept-Encoding - gzip, deflate 
Accept-Language - en-US,en;q=0.5 
Content-Length - 26 
Content-Type - application/json;charset=utf-8 
DNT - 1 
Host - localhost:9200 
Origin - null 
User-Agent - Mozilla/5.0 (Macintosh; Intel Mac OS X 10.11; rv:44.0) Gecko/20100101 Firefox/44.0 

有人可以請建議我在做什麼錯誤在上面?

+0

可以嘗試把它寫在雙引號? – alpert

+0

如果添加雙引號,elasticsearch將無法啓動。 – JSB

回答

0

你似乎有一個小的錯字。

它應該閱讀

http.cors.allow-origin: /https?:\/\/localhost(:[0-9]+)?/ 
          ^
          | 
          add this 

即您的?,這意味着之前缺少s「HTTP或HTTPS」

+0

嗨纈氨酸 - 我確實已經嘗試過 - 實際上似乎沒有什麼改變。 – JSB

+0

我懷疑查詢不是來自本地主機,但可能是127.0.0.1,這可能嗎?你可以在發送查詢時檢查你在Firefox開發者工具中看到的內容嗎?請求者使用什麼主機? – Val

+0

添加上面的reqeuste標題 - 似乎使用本地主機。也嘗試在yml文件中使用127.0.0.1,但也不好。 – JSB