我正在使用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
有人可以請建議我在做什麼錯誤在上面?
可以嘗試把它寫在雙引號? – alpert
如果添加雙引號,elasticsearch將無法啓動。 – JSB